That "Prostitution is legal in the UK, but not in a brothel or via a pimp" is somewhat misleading.
In England & Wales, prostitution is indeed legal and it's only the people owning or running (or allowing on property they control or assorted other things) a brothel who break those laws: both clients and prostitutes there are still behaving legally.
Similarly, when it comes to agencies, it's just those running them who are 'controlling prostitution for gain' and thus behaving illegally.
(There is an offence of paying for sex with someone who is coerced, but as far as I can see, no-one's ever been charged with it.)
Despite those, there are plenty of brothels and escort agencies. Why? The police have better things to do, such as dealing with street work (where soliciting both ways is illegal). If you don't annoy the neighbours, some forces will invite brothel owners onto a committee to discuss how to run them better rather than charging them.
Scotland used to be more or less the same. When all its police forces were combined, the one in Glasgow - which hated prostitution - ended up in charge and so they've done things like harass people working legally.
Northern Ireland has made buying sex illegal, as a pointless bit of gesture politics. Hurts the people it pretends to protect, but makes the law makers feel happy.
I don't claim sex work law makes sense. Especially as no money need be involved for somewhere to be a "brothel", just more than one person being sexual with a variety of others.