The foam on top of lentil soup is primarily caused by the release of proteins and starches from the lentils as they cook. It's completely harmless and can be skimmed off if you don't like the way it looks.