At the end of season 3, Barry entered the Speed Force, filling a gap in the "Speed Force prison" built for Savitar that would destabilize the universe if left empty.
"That will be addressed in the season premiere," executive producer Todd Helbing said of the Speed Force prison. "We simultaneously live by the rule that cool trumps logic, I think most shows do that but we don't want to just gloss over anything ever. So, we want to pay off both the questions that we set up and also find a good solution and a satisfactory solution for any sort of problem that we write ourselves into. But we try to do it in the most fun way possible."
In this case, that way is that Cisco and Caitlin designed a device that could be thrown into the Speed Force with an approximation of Barry's bio-electric code, essentially fooling the Speed Force into believing Barry was still there even while he escaped to become The Flash again.
It isn't that easy, though: after being spat out of the Speed Force, Barry was naked and disoriented; eventually picked up by the police, it took most of the rest of the episode to bring his memories and personality back.
Eventually it was a shock to his system that brought him out of his haze: when Iris was kidnapped by the Samuroid, Barry's eyes filled with lightning (Speed Force?) when he was told, and he filled with enough power to blow the glass out of a containment cell in the pipeline at STAR Labs. When he arrived by her side to rescue her, he had suited up in Cisco's latest installment of the Flash suit and was ready to fight, with no real explanation offered.
When asked, Barry said that even he did not remember what had caused the change -- that he did not remember anything between when he left for the Speed Force and when he was rescuing Iris.
The Flash airs on Tuesdays at 8 p.m. ET/PT on The CW.