In both cases, the only reasonable meaning is equivalent to "right away". A good rule of thumb is that usually "gleich" means "same" if it there is a form of "haben" or "sein" other than as auxiliary verb for the past tense in the sentence ("Die beiden sind gleich", "Wir haben gleich viel Eis") and "right away" when it referes to a verb other than an auxiliary verb ("Die beiden gehen gleich los", "Nach dem ersten Eis haben wir gleich noch eines gegessen").
On a more abstract level, "gleich" means "same" when it referes to a comparison (in that case it can mean "same", "similar", equal" or somthing comparable) or an evaluation (in that case it means "all the same" or "to not care") and "right away" if it referes to an action or state of beeing (in that case there is usually a more or less implicit timeline layed out).
To evaluate your examples:
Nadine, lieg nicht gleich wieder in der Sonne!
She has been lying there, than something happened and she may or may not go lie there again. "Gleich" referes to "lieg" (imperative of "liegen").
Ich mag kein Eis, und du?” – “Ich schon, ich möchte mir gleich eins kaufen.
Speaker two expresses their plan to buy an ice soon. "Gleich" referes to "kaufen".