The Royal Mail in the UK is definitely allowed to open mail as a last resort to figure out where it should be returned to, the National Returns Centre undertakes this work. If the contents turn out to be something that isn't returned (e.g. a newspaper or magazine) it's destroyed, if it's a letter the NRC will try to figure out where it came from and send it back there.
Most commercial mail carries an return address written on the reverse to avoid the need for this, and of course letters you write by hand should also provide a return address in principle although you're much less likely to send stuff to the wrong address than a commercial operation - when I heard my cousin had moved just before Xmas I didn't send her a card, because there's no point sending it to the wrong place and hoping it gets forwarded eventually, it's just an Xmas card.