Passenger side rear brake light works when lights are off, but does not when lights are on. In looking at both lights while on, the passenger side seems to burn much dimmer than the driver side.
Is the bulb the correct one? If you aren’t sure, swap bulbs left for right and see what it does.
It may be that the chassis ground to the passenger side light is bad. This would cause the condition you are reporting. Check to see if there is a wire that goes to the body of the car from this passenger side light. If so, clean the connection at the body of the car and see what happens.
Is this a two function lamp with a dim setting for normal driving and a bright setting for the brakes? If so replace the lamp. Get the right replacement.