The legality will depend a lot on what songs you're interested in capturing the audio tracks of. For private personal use, the legality of capturing the audio tracks is little different to hooking up a tape recorder to a TV to record the audio from.
The main problem you'll likely encounter is the audio quality will not be great, certainly not anything like music obtained from an official source, since YouTube uses a rather low bitrate on its music.
Before you can extract the audio, the first thing you'll need is a tool to download the YouTube video you're interested in. This will result in an FLV file being saved. Afterwards, you need a tool to export the sound track to MP3 before you can play it on your MP3 player.
My favourite downloader is the DownloadHelper add-on for Firefox (link), which is freeware. You need to use the Firefox web browser for this to work. Once installed, open up the YouTube video you're interested in. A small multicolour icon will start rotating next to the homepage icon. Click the down-arrow next to this, select the YouTube FLV file and then click 'Download'.
Next, you need a tool to export the sound track from the FLV file. The freeware utility WinFF will do this (link) In this utility, add the FLV(s) you downloaded, select "Audio" in the "Convert To..." drop-down and select "MP3" for the Device Preset. Select the output folder and then click 'Convert'.