Legality of hanging things outside your window?
Nothing to do with building codes, unless you are hanging an addition to your house out the window.

Your own (single-family) home on your own lot (piece of land) - depends what you have (or don't) for a home-owner's association, or if your house is subject to some sort of restrictive covenant such as a historic preservation district.

A home that is part of a multiple-dwelling unit where you own the space in the building, but not the land - more likely to have some other rules and regulations impacting what you can do from your windows, in the interest of protecting other people.

Note that on your own property you still have an interest in protecting other people, but it comes mostly from the fact that they can sue you, so if you plan to hang something very dubious safety-wise out the window, your insurance company may decide that you are a bad risk and cancel your coverage or raise your rates.