Torrenting itself is not illegal; it's just a method of file transfer using multiple servers (the downloaders act as servers).
Any legal issues around using it relate to the content. If you do not have the legal right to download or upload material, then downloading or uploading it via Torrent is illegal.
Canonical (the company that develops Ubuntu) provides links to obtain Ubuntu images by torrenting. Obviously, you have the right to download it, so it is not illegal to do so by this method.
According to Wikipedia (emphasis added):
The use of the BitTorrent protocol for unauthorized sharing of copyrighted content has led to a variety of novel legal issues. While the technology and related platforms are perfectly legal, law enforcement and prosecutorial agencies worldwide are developing new tactics and increasingly pursuing ways to address this avenue of infringement. Notably, the use of BitTorrent in connection with copyrighted material may make the issuer of the BitTorrent file, link or metadata liable as an infringing party under the copyright laws of various governments. Similarly, the use of BitTorrent to procure illegal materials could potentially make end users liable as an accomplice under various laws.