My brake light will go
Yamaha motorcycles of this vintage are notorious for having flaky electrical connections. Take a look at your fuse box. Do you still have the original fuse block, or has someone gradually (or all at once) replaced the stock fuse blocks with in-line fuses? I have owned a number of '78-82 Yamahas, and I've had to change out the fuse block on every single one of them.
While that might have some bearing on your tail light issue (have you checked with a voltmeter to make sure the bulb socket is getting power? Sometimes, there's enough corrosion in the socket to prevent good contact with the bulb), the more likely culprit is corrosion in one or more of the bullet connectors piecing your electrical harness together. In terms of troubleshooting, I would actually start with the ground side, as a poor ground gives exactly this type of flaky "sometimes on, sometimes off" performance.
Start with your brake bulb, rather than your tail light, because you know that power is at least sometimes getting to that socket. Find the black negative wire coming out of the socket. Even before you do any kind of wiring trace, clip a temporary ground wire onto that terminal of the bulb socket and a frame or engine bolt--or even right back to the negative terminal of the battery. There's not a lot of amperage being passed through this bulb, so you can use a thin, Radio Shack level jumper cable or simply make your own with two alligator clips and a length of insulated wire. At any rate, once you've grounded the bulb socket, try the brake switches again to see if the bulb now lights up reliably. There's a pretty good chance that it will. If that's the case, trace the black ground wire to each of its friction fit connections. Pull each connection apart, clean the connectors, and reseat everything. Continue until you've gotten all the way to the official ground. Or, if you get tired to this exercise, you can splice a fresh ground into the wire. As the wiring bundle has a common ground, this may actually help a number of components, not just your brake light or tail light.
If adding a good ground doesn't fix your intermittent bulb problem, you'll need to trace the positive side of things. Here, based on my experience with XS650s, I would suggest that you start tracing at the fuse block. I don't know what kind of metal Yamaha used, but those fuse blocks get brittle and don't always keep a good connection with the fuse or with the wires feeding into the fuse block, even if they look good in a visual inspection. Using the continuity function (or the volt meter function, with the negative cable clipped to ground), start tracing the wiring to each connection point, again pulling apart each connecting block to clean the connecting pins. Because Yamaha wraps all its wires into bundles, this will be frustrating work--it'll be easiest if you just start with testing each connecting block and checking from continuity from there. That way, you don't have to unwind any of the wrapping unless or until you find a bad link. Yamaha wires rarely shed their insulation; problems are almost always caused by tarnish at the connectors.
Good luck finding the bad connecting block, bad bulb socket, or bad ground that's keeping your lights from operating properly. The XS650 is a bulletproof bike that's great fun to ride. The electrical gremlins are a relatively minor problem in the grand scheme of things.