Designs vary but I'd take an educated guess that the wire was attached to the terminal where the tab on the base of the bulb its as marked by the arrow in my drawing.
View attachment 478438
The red stuff insulates it from the rest of the bracket which would have been grounded using the body of the lamp and in connection with the frame of the bike. It should be soldered or possibly riveted into place. Someone handy with a soldering iron could easily fix this. Or if that rivet is hollow, you may be able to bodge it with a bare wire fed through it so it contacts the bulb but soldering would definitely be more reliable.
If the front lamp works, I can think of several different reasons why the tail lamp won't work.
1. Probably because of a bad connection on the bit of the wire and tab that have now broken off.
2. Blown bulb - as mentioned, swap with the front temporarily or test it on a battery. Don't ride with the rear bulb in the front as it will blow very quickly but a quick spin of the wheel to check operation won't do any harm.
3. The light most probably grounds through the frame anyway even if an additional wire is used (for reliability). In which case you have caused a short circuit.