I just tested out your code. The problem occurs because as soon as OnGUI() is called, it looks at the Boolean value and immediately prints the GUI Button. So in effect there are 3 Gui Buttons being loaded. So the one with Icon is always loaded first. I modified the code where you actually check whether it is ready to load the GUI. Hope it helps.
var imageText : boolean = true;
var icon : Texture2D;
var readytoload = 0;
//button that control
function OnGUI(){
if(GUI.Button (Rect (10, 210, 100, 15), "IMAGE OR TEXT"))
{
readytoload = 1;
imageText = !imageText;
Debug.Log(imageText);
}
if(readytoload)
{
if(imageText)
if (GUI.Button (Rect (5, 100, 50, 50), icon))
{
imageText = true;
Debug.Log("Icon");
Debug.Log(imageText);
}
if(!imageText)
{
if (GUI.Button (Rect (205,100, 50, 50), "Text"))
{
imageText = false;
Debug.Log("Text");
Debug.Log(imageText);
}
}
}
}