How do I know the public key of the person I need to pay? As per the answer to this question, we cannot retrieve the public key of a user.1)How does my wallet get the value (public key/public key hash) to which I need to make the payment?2)What is the harm in exposing an address's public key?
I read through both questions, so please correct me if im answering the wrong question.


The user who you want to pay must send you their public key (or QR to scan) in order to send money to them. This is, of course, unless their public key (wallet) is listed on a public website. Please see https://en.bitcoin.it/wiki/Help:Introduction#Sending_payments
In general*, there is no harm in exposing a public key. This question on crypto stackexchange goes into more detail Is exposing a public key bad?