I have seen many installed in bathrooms, under the sink cabinet, or up on a shelf, the only code to me would be a plumbing code for the proper venting of the pressure relief valve.
there are water heaters that are design to be mounted in a bathroom, and they are UL listed, most are insta-hots under the sink.