Is the phrase “Did you do that on porpoise?” a pun? It doesn’t exploit multiple meanings of the same word but instead uses a different word that sounds similar
Yes, it is a pun. It is a homophonic pun.
The homophonic pun, a common type, uses word pairs which sound alike (homophones) but are not synonymous. Walter Redfern summarized this type with his statement, "To pun is to treat homonyms as synonyms." For example, in George Carlin's phrase "Atheism is a non-prophet institution", the word prophet is put in place of its homophone profit, altering the common phrase "non-profit institution". Similarly, the joke "Question: Why do we still have troops in Germany? Answer: To keep the Russians in Czech" relies on the aural ambiguity of the homophones check and Czech. Often, puns are not strictly homophonic, but play on words of similar, not identical, sound as in the example from the Pinky and the Brain cartoon film series: "I think so, Brain, but if we give peas a chance, won't the lima beans feel left out?" which plays with the similar—but not identical—sound of peas and peace in the anti-war slogan "Give Peace a Chance".
The article lists other types of pun : homographic, compounded, recursive and visual.