The story
Possibly from piss-proud (“falsely presenting as successful”). In which case taking the piss out of would mean deflating their false pride, usually through disparagement or mockery. As the piss-proud metaphor became dated, taking the piss out of someone came to refer to disparagement or mockery itself, regardless of the pride of the subject. Eventually the shortened, intransitive form taking the piss became common.
Etymology from Wiktionary, CC BY-SA 4.0.