I can't speak for the UK but in the USA our laws technically apply no matter where a citizen is. US law trumps foreign laws and you could be prosecuted when you return.
In some cases they have done this, such as in the PROTECT Act of 2003 which contains a prohibition on child sex tourism. But there is no general assumption that US law applies everywhere.