(Source: Sefer HaChinuch 576 in the Venice edition, 560 in the Frankfurt edition)
The commandment in that verse doesn't really refer to entering the temple — the language is that he can't enter the assembly. This is the way of saying that he can't marry into the nation. However, to live in the same cities as them, to trade and do business with them, etc., is permissible.
The reason for this is because the rough definition of a bastard is that he was born from an adulterous relationship, with thoughts of impurity. If so, the nature of the father is certainly hidden in the son, and so G-d made the rule that he can't have any more offspring to keep them away from us,(*) because G-d keeps us away from all kinds of bad things.
And as for the question of why the tenth generation is any different than the seventh or eighth, the truth is that it means forever (Rambam, Isurei Biah 15:1).
(*) msh210 believes that the correct reading is "to keep him (the bastard) away from us," and his belief seems to me to be the correct one.