Couple of things, first check the bulb on the left rear lamp, it's a double filament, if the tail lamp portion broke it could be laying on the brake lamp portion, and cross feeding to the right lamp, when the turn signal is on.
The lamps occasionally not working when the brake is applied could be a poor ground.
Also check to see if maybe you have a bad flasher.
Lastly I'd say if all else is good, you have a bad turn signal switch.
97 Sahara, 74 Renegade, 72 CJ5, 55 Willy's (the Beast) Boss 302, 6:34 gearing, Bose 901 speakers.
God I miss that Jeep. Forgot the kinda Jeep, 80 SX4.