It sounds like to did apply the foam correctly from the start so I have no idea why it would shrink up.
Did you clean the glass with anything before applying the foam? I use Wipe-out since I know it doesn't leave a residue behind. Virginia would also work.
One thought here would be to see if you can inject some silicone in behind the piece coming off to secure it. Maybe prop it into place with something while the silicone dries.