The other answers already covered why the joke may not be so well received.
However, I would not go so far to say it does not make sense at all (because I appreciated it, even if it is after your explanation).
Indeed, this sort of humour is specific and not appreciated by everyone, and sometimes it is humourous exactly because it is so unfunny.
In Chinese, certain sorts of jokes are commonly known as 冷笑话 (lit. cold jokes), which literally means jokes that would not cause any reaction in the audience (冷场, lit. cold venue).
A common theme in some of these jokes is to uncommon interpretation or parsing of homophones, homographic heterophones and/or ambiguous sentence structures.
The (anti-)humour element relies on often absurd interpretation of words and sentences that are often obviously illogical.
For example, a rather well-known humour account (冷兔, as you can infer from the name they are known also for cold jokes) today just (re)posted the following:
知了掉进泉水淹死,也算泉下有知了 (le)。
知了掉进泉水淹死,也算泉下有知了 (liǎo)。
Interpretation 1: If a cicada fell into a spring and died, it still lives after its death (lit. knows under the spring; the yellow spring = where people go after death).
"Interpretation" 2: If a cicada fell into a spring and died, then there is a cicada under the spring.
which in some way is like the joke you tried (a non-obvious pronunciation).
These jokes are not funny to many people because they require further process of the information since the "humour" is not obvious and initially absurd. In this case, one thing you may do is to actively ask people to think, for example, by making it a 脑筋急转弯 (brain teaser):
问:为什么这个人对医院里的病人脏话连篇?
答:他是一个医生,对一个病人说他心脏不好,又对一个病人说他肝脏有问题。
or
问:为什么说这个医生不礼貌?
答:因为他脏话连篇,对一个病人说他心脏不好,又对一个病人说他肝脏有问题。
By actively inducing people into the "thinking mode", the humour may be more easily accepted.