Of course always lock your doors but I also got a wooden dowel to put in the sliding track of my sliding glass door so that, if someone has somehow defeated the lock, when someone tries to open it from the outside they simply can’t. I also strongly recommend this for front doors: Portable Door Lock Home Security Door Locker Travel Lockdown Locks for Additional Safety and Privacy Perfect for Traveling Hotel Home Apartment College https://www.amazon.com/dp/B08L7DNXT9/ref=cm_sw_r_cp_api_i_XH114VB2ZN26G31E7ZTT?_encoding=UTF8&psc=1
Stay safe friend!
If you prefer not having to knock, you could use an extra lock that prevents anyone from coming inside the bathroom while it's occupied. Something like this --->
https://www.youtube.com/watch?v=3lRbIoMckJQ
https://amazon.com/Portable-Security-Additional-Traveling-Apartment/dp/B08L7DNXT9/
If I were in your position, I'd get a key doorknob for that bathroom with 2 keys. One key for you and one key for your roommate. Don't give a copy of the key to the upstairs roommate so that he won't have a choice but to use his own bathroom. Since he isn't willing to listen to reason, I think this is the only option you have left.
If you're worried about your roommate coming inside the bathroom when you're there because they also have a key, you could either ask them to knock first or you could use something like this to prevent anyone from getting inside the bathroom when it's occupied:
https://www.youtube.com/watch?v=3lRbIoMckJQ
https://amazon.com/Portable-Security-Additional-Traveling-Apartment/dp/B08L7DNXT9/