The episode you're thinking of is called "The Doctor's Wife".
In this episode the Tardis'sTARDIS' energy is placed into a body of a female named Idris by a sentient planetoid (named House) that wants to leave the pocket universe it lives in. In the past it has lured other timelordsTimelords to itself and consumed them. Using a timelordTimelord distress signal it lures our Doctor to itself. When the Doctor shows up "House" takes over the TardisTARDIS and attempts to leave its pocket universe. While doing so it amuses itself by torturing Amy and Rory. Making them see things by manipulating time and space around them (the parts to which your question was referring). It is to the best of my knowledge the first time the Doctor has been able to directly interact with the "Tardis"TARDIS and literally has a heart wrenching ending. This episode is one of my favorites.