Free PSN codes are available online from websites that choose to give them away in return for a small task that they might choose to give to their visitors. So basically once you are on their website trying to follow PSN codes online they will ask you to complete a small task and this could be anything.
Many websites usually will simply ask you to complete small surveys which help them understand consumer needs better. So it is up to you whether or not to complete such a survey but if you choose to complete your survey you will be offered free PSN codes as a reward at the end.
However, some websites that give away free PSN codes cannot be trusted because even after you complete surveys they would not have any PSN codes to giveaway to you and the sad thing being they would not disclose this before you complete your survey.
The onus would, therefore, be upon you to be careful when proceeding with such an action. If you want to try whether a website can actually give away free PSN codes what you could do is just fill in the survey with any information that you can come up with. Do not initially reveal any of your personal information unless of course, you can trust the website in question.