A magnet link is a URI that identifies content by cryptographic hash rather than by a normal file URL. In BitTorrent, the key element is usually the xt=urn:btih: value, which refers to the torrent infohash.
A torrent file is a small metadata file. A magnet link is a URI-style pointer that tells the client what hash to look for. Both can be used in BitTorrent workflows, but magnet links fit well with decentralized lookup.
The link format itself is neutral technology. Legality depends on the content being shared and the rights attached to it.