In Tennis, if the first serve is not legal a "fault" is declared. If the second serve is again illegal ("double fault"), the other player gets the point. If the ball hits the net cord during the serve, but is otherwise legal, a "let" is declared and the player serves again. There is no limit on the number of lets in a service.
Anyway, a second-serve cannot be an injustice or unfair, because both players adhere to the same rules; if only the player serving first could serve twice or similar, it will be as such, but since both players are allow 2nd-service attempts it is perfectly fair.
As to the logic behind it (in tennis at least), proper serves requires mastering of a difficult technique, and so giving players a 2nd attempt at this allows more margin for error. This may be why there is no such thing as a "2nd serve" in table tennis; there is no requirement to hit the opposite side of the court, so you can say service is easier.