Remove the tail lights, clean the bulb socket and the bucket, apply some dielectric grease to the socket and reassemble. The tail lights are notorious for losing ground, but this is remedied with a good cleaning.

Follow up by checking the two wires that attach to the brake light switch located at the top of the brake pedal. The brake light switch can be adjusted to work properly as the brake pedal is pressed. Sometimes the wiring is kinked or pulled from the blade connectors on the brake switch while working under the dash.

Good luck with your brake light repairs. I hope this helps.