When it comes to hiding your doorbell transformer, it needs to be in open air and cannot be enclosed. One example of where to hide your doorbell transformer, is off the attic light socket.
Alternatively, you can hide it in a closet, behind and above the sliding door, or in your basement. However, as a rule of thumb, your doorbell transformer cannot be hidden behind a wall as there are regulations that advise against this due to safety hazards. This is mainly because the doorbell transformer generates heat.