I was playing Left 4 Dead 2 and I saw a player paint a graffiti on a wall (I also saw it done on Team Fortress 2)
How is this done? What is it purpose?
Is it different on those two games or is it something at the engine level?
The place you configure your sprays is in the options menu, under multiplayer.
From this place you can import an image of the proper dimensions, which will show up when you use the spray command (default T) in game.
The default key for sprays is T in TF2. It is likely the same in L4D, though if you look through the keyboard settings it should be there.
Bear in mind that some servers restrict sprays to avoid objectionable (porn or other shock) sprays. If you're on such a server, when you attempt to throw up your spray, the noise will play but nothing will happen.