Yes, it is legal - and it will be faster than $(".myclass").css({background: "#FF0"}) because you only interact with the DOM once rather than N times (where N is the number of .myclass elements on the page.) Also, it will be applied to future .myclass elements automatically.
The disadvantage is that you can run into specificity issues, so you have to make sure to architect your CSS in a way that will ensure that you can override the background with a single class selector. (jQuery's css function, since it sets the element's style attribute directly, has some of the highest specificity by default and so avoids this particular problem).
For example, if you had this CSS somewhere in your linked styles:
#some-id .myclass { background: #000; }
then the DOM-heavy $(".myclass").css would override the background, while the dynamically injected style (injecting just .myclass { background: #FF0; } would not).
The other disadvantage is that old-IE (<=8) only allows you to create 31 of these "dynamic" style sheets. In IE >= 9, this is not a problem.