If you are desparate to kill time you could clear security in A with United and then take the airside bus to B and visit the LH EWR lounge. Not that the LH lounge is something to write home about. LH themselves indicate that getting to the lounge may not be possible:
https://www.lufthansa.com/de/en/arrival-services
Complimentary: a stay in one of our lounges
Enjoy a complimentary stay in one of our lounges after your flight. Here, you can freshen up or prepare for the business of the day. Access to Lufthansa Business and Senator Lounges is granted to First Class passengers and HON Circle Members and Senators arriving on a Lufthansa, Star Alliance or codeshare partner flight.
[...]
Please note that it is not possible to visit a Lufthansa lounge after arrival at some Lufthansa destinations due to official regulations or structural conditions.