Spray foam is a terrible idea on a panel. For a million reasons. My panel is in the corner of my room too. It isnt the builder who decides its the utility company.

Is the panel flush mount or recessed in the wall? For flush mount put neoprene weather stripping around the door cover. No more rattles.

For recessed, build a door for the whole thing flush with the wall that meets these criteria:

Must be identified as covering the panel so anyone can locate it to turn breakers off. Must not be locked ever.

Must have a clear unobstructed work area of no less than 1m once the cover is open. More is obviously better.

Must be of a material appropriate for concealing electrical equipment. Ie fire rated.

Its really a good idea to have your GC ask the inspector what will fly in your area.