In a recent project I encountered a very long legend in a fieldset from a node add/edit form. Instead of wrapping, it forced its way into the right-hand sidebar and was generally causing a mess of the layout.
In looking into this I discovered that legends don’t wrap by default, and so I needed to toggle that behavior via CSS. You can do it globally using the following CSS
Because it’s a global setting, if your legend ever gets too long, then this declaration causes it to wrap. If you wanted to target a specific instance, than just change the declaration to suit your needs.