Generally speaking Modding is not illegal unless the publisher/developer explicitely prohibits modding of their games. For the most part publishers/developers generally allow people to create mods. There are even those who encourage it by providing a tool for it. Like the GECK for Fallout 3.
What's prohibited as far as modding is concerned, is the use of copywrited material without the permission of the original creator(s) and illegally profiting from a commercially copywrited game with custom mods. An example, would be to take Fallout 3 make your own mod to create a "fantasy" mod and then selling the game as if it was your own creation.