I want to switch my brakes to have the front brake be on the right and the rear on the left? How do I detach the cables and reattach to the opposite lever?
Assuming you have cable operated brakes, the basic answer is you have to detach the cables at the brake calipers, and pull the cables out of the housings through the levers. The levers hold the cable via a boss swaged onto the end of the cable, so that’s the only way to get the cables out. You can then switch which levers the the front and housing rear housings run to and re-thread the cables.
Cable strands often get unraveled by the pinch bolts that hold the cables on the calipers which makes the cables impossible to thread back through the housings, so new cables from the outset are a good idea.
You may encounter difficulties with switching the housings between levers depending on the existing housing routing.
You also need to know how to re-adjust the brake calipers when you re-attach the cables, but good quality guides are easily found on the web.
If you have hydraulic operated brakes things are more complicated. Hoses can be swapped but you have to deal with avoiding spilling hydraulic fluid and bleeding both brakes afterwards.
It may be quick and easy with free running cables, although I'd get suitable new cables before starting the work. They're easier to install than trying to re-install used ones. While you're at it also check the housings. It may be cheaper to buy a set that comes with all the bits and small parts required than get separate items.
It will be more difficult and time consuming with housings hidden under bar-tape and/or running internally through the frame. There would be numbers of videos on the net that show how to replace brake cables which is basically the same procedure.
Any lever can pull any brake, front or rear doesn't matter. But usually it is a matter of convention to have the right lever pull the front brake in countries with right-hand traffic. So maybe you should check if this not a legal requirement under your traffic laws before changing the set-up.