In a similar manner to American Graffiti and Scorsese's earlier Mean Streets, the songs served roughly the same purpose as a composed musical score.
While an official soundtrack was released at the same time as the film, it only featured a small fraction of the songs used.
Scorsese chose the songs for Goodfellas only if they commented on the scene or the characters "in an oblique way".
[1] The only rule he adhered to with the soundtrack was to only use music which could have been heard at that time, deciding that he could use any song released before the scene in which it played took place.
For example, he had "Layla" playing on the set while shooting the scene where the dead bodies are discovered in the car and the meat-truck.