^ Hope you see this before its too late. ^
Spray foam is extremely flammable. A fault in your panel would cause big fire concerns. The best thing to put in direct contact with a panel is nothing at all. Failing that I would do roxul. It wont burn under a direct flame and can be removed if necessary.
Spray foam also makes maintenence or future wiring impossible.
Exactly. No insulation inside the box at all. If it is mounted like most boxes, it shouldn't need anything around the outside as it should be solid an secure to at least 1 stud, and somehow tied in to a 2nd stud, which wouldn't be where the vibration is coming from anyway since they should be solid.
I still say it is the door rattling, but I am not there to actually hear it.