1. I have post #1 and post #3, with post #5 quoting post #3
2. I merge post #1 and #3 together, with post #1 being the target/remaining post.
Post #5's quoted content still links to post #3, which when clicked gives you a 404 page not found.
I would think that during the merge posts process, the system should support hyperlinks to the 'disappearing' post, so that it still works instead of giving a 404 page.
A possible solution being:
i) during the merge process, keep the record in xf_post for post_id #3
ii) set message_state to 'merged' for post_id #3
iii) add a column in xf_post for 'merged_post_id' and populate this with the target post (#1 in this scenario/example)
When XF gets a URL request for https://xenforo.com/community/posts/3/ it would see that 'message_state' is merged, and instead of returning a 404 it would return a 301.
The same solution could apply for merged threads too.