The literal sense is transparent:
顶 'to push/butt against' +
针 'needle' → the metal cap that takes the push of the needle when you sew. The rhetorical sense (also written
顶真) extends the same image: each line 'pushes' the next using the same word at the seam.