The episode you're thinking of is called ["The Doctor's Wife"](https://www.imdb.com/title/tt1721226/). In this episode the Tardis's 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 timelords to itself and consumed them. Using a timelord distress signal it lures our Doctor to itself. When the Doctor shows up "House" takes over the Tardis 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" and literally has a heart wrenching ending. This episode is one of my favorites.