Tony has a mental breakdown and ends up locked in Shields prison (which is where Loki would be) and since Loki's his only companion they are forced to be together all the time and they fall for each other. Loki being loki makes it seem like he's only befriended him for a way to pass the time. Tony and Loki would also both be trapped inside their minds and Tony will at some point see Loki's true insanity (cause loki will have already been in there for years)