Is their a Radiator Safe expanding Foam?
See if you can get some drywall scraps (you certainly don't want to buy a whole sheet for this) and fill in the corner, then fill the remaining gaps with drywall compound (both of which are fine with hot metal.)

For a dire kludge if you can't manage to beg some scraps you could build up the whole thing from drywall tape and compound, but ANY place that's being drywalled generates scraps (and they are throwing them away) - anyone who has needed to do a large repair probably has the remaining part of the sheet they had to buy sitting in a basement or closet - you should be able to find some.

You might want to use silicone caulking between the drywall patch and the pipe itself, just because it will be less prone to cracking (so more resistant to bugs) than drywall compound right up against a hot pipe.

As to your question, yes, any of the polyurethane foams (read the label) are safe with a hot pipe, and you could potentially use the "low-expansion" type to augment this approach to sealing the wall - but I would not recommend it as the only method. Actually, given that you are in an apartment (and that a single can will probably do you) I'd suggest the "fireblock" type of foam if buying a can of foam.