Electrical panel installed in bathroom

Here’s the code reference:

240.24(E) Not Located in Bathrooms.
In dwelling units, dormitory units, and guest rooms or guest suites, overcurrent devices, other than supplementary overcurrent protection, shall not be located in bathrooms

The bathroom one is super clear, section (E).
The closet one less clear, section (D):

240.24 Location in or on Premises
(D) Not in Vicinity of Easily Ignitible Material
Overcurrent devices shall not be located in the vicinity of easily ignitible material, such as in clothes closets.

Some places interpret clothes closets as an example of a location that might contain ignitable materials.

When the panel is located out of the closet, nothing prevents a homeowner or renter from putting an ignitable poster, picture, rug, wall hanging or whatever in front of it. In fact, that’s more or less guaranteed to happen. Many sparkies place subpanels exactly like pictures, at the right height for exactly that reason.