The words that are translated as "him" in your two examples do not have the same function. In Je vais le voir, le stands in for a third-person singular masculine direct object. Generally speaking, the direct object is not prefixed with a preposition, when a verb is applied to it. Thus, these are acceptable substitutions:
Je vois la poule. ➔ Je la vois. (La is the feminine equivalent of le.)
Il mange le croissant. ➔ Il le mange.
Il n'aime pas son beau-père. ➔ Il ne l'aime pas.
Meanwhile, these are not acceptable:
Lui is used as the third-person singular indirect object. (It is the same for both masculine and feminine referents.) Generally and loosely speaking, indirect objects are prefixed with the preposition à. Thus, the examples of unacceptable transformations could be fixed to be:
However, in your example of C'est pour lui, lui is a pronom tonique, not an object of any sort. Pronoms toniques follow certain prepositions; are used when referring to animate objects, in certain constructions; and can also be used for emphasis. Some examples:
Moi, je ne l'aime pas. (Moi is the first-person singular equivalent.)
Il achète ce livre pour lui.
Je pense à toi. (Toi is the second-person singular equivalent.)
As shown in the last example, they can still sometimes function as objects, but in an example such as pour lui, that is not the case, and they are instead forming part of an adverbial phrase.