If they are vinyl, I would lower the top sash of the operating window and look at the top of the frame and see if there is a tag there that tells you where they came from.
You might also look on the sides of the sashes to see if there is a tag there if they tilt in.
I would not spray any foam in the gaps that you have until you have determined where the windows came from. They may still be under a warranty or at least, the manufacturer may want to know that thier windows are not being installed properly by the contractor who sells them.