***NB: Doing anything to change the shape of a helmet, including/especially the foam, will impact the overall protective capacity of the helmet, and is not likely within the boundaries of "recommended" by any [bicycle helmet] manufacturer*** Having said the above, I did learn this technique from a motorcycle shop who in turn learnt it from Arai - the inventers of the motorcycle helmet. So at some level at least, it appears to be "manufacturer kosher".
** Officially I do not recommend that anyone do this, ever.
This only works/works best for very small changes where you might have a hot spot or a little bit of minor pinching - I wouldn't recommend it to change the overall shape of a helmet. Specialized tools exist in the moto industry but a teaspoon or anything hard/smooth/gently curved can be used. Essentially you're using the tool to "dent" small areas of the foam in order to create more space. I'm talking a mm or two max - not a big compression by any means. Take the spoon and using your thumb or fingers, press the back into the area that you want to expand, "stroking" or "painting" the area in small sections until you've flattened/depressed it by a tiny amount. If the average thickness of the foam is 1" and you're compressing the foam by 1mm you're losing ~1/25 of the overall thickness in that area. I'm sure the math doesn't translate to 1/25 less protected and bear in mind that this is done over a tiny area of the helmet - not the whole thing.
It's certainly better to have a helmet that fits perfectly out of the box with no modifications needed - but if it's really damned close this can be the difference between a helmet that feels good for 30min/1hr and then starts to hurt/give you headache and one that you can wear all day.