I'm from the UK and entered Germany on September 6th 2022, and got a residency permit on the 20th of November 2022. My visa expires on the 31st of May, and I am wondering if I go back to the UK after my visa expires, will I be able to re-enter Germany again right away (June 1st or 2nd) or will I have to wait 180 days?
I'm going to assume your residence permit is currently valid. In this case, you do not need a visa and your presence in Germany is not limited to 90 days in any 180-day period.
If you do not have a valid visa or residence permit and your 90/180 limit is fully exhausted then you must remain outside the Schengen area for 90 days (not 180) to reset it fully. (You may be able to return sooner for a shorter stay than 90 days depending on your recent travel history.)