Japan shocked Germany in the earlier game in the group, recording a 2-1 victory, to move to the top of the section, but they have now been replaced by La Roja, who proved to be far too strong for Costa Rica.
Ferran Torres netted twice during a dominant performance, while Dani Olmo, Marco Asensio, Gavi, Carlos Soler and Alvaro Morata were also on the scoresheet for the 2010 world champions.
Luis Enrique's side will continue their Group E campaign against a wounded Germany on Sunday, while Costa Rica will be bidding to bounce back from the loss when they face Japan on the same day.
Spain had a brilliant chance to make the breakthrough in the fifth minute when Olmo met a deep cross from Pedri, but the attacker volleyed just wide of the far post.
Pedri then set up Asensio in the eighth minute, and the Real Madrid attacker, who started at centre-forward, just missed the far post, with La Roja dominating the contest early on.
The breakthrough arrived in the 11th minute when Olmo collected a pass from Gavi before turning and producing a brilliant finish over the onrushing Keylor Navas.
Spain then doubled their lead in the 21st minute, with Asensio sweeping a low Jordi Alba cross into the back of the net, with Navas unable to keep it out despite getting hands to the ball.
Enrique's side were awarded a penalty in the 29th minute of the contest when Alba was brought to the ground by Oscar Duarte, who could not resist challenging the Barcelona defender.
Torres was the player to step forward, and he made it 3-0 by sending Navas the wrong way from the spot, with Costa Rica having the match taken away from them before the end of the first half.
Spain's final chance of the first period fell to Asensio, who again broke into a dangerous position, but Duarte did just about enough to put off the attacker, with the score 3-0 at the interval.
Asensio then fired over the Costa Rica crossbar in the early stages of the second period, but Spain had a fourth in the 54th minute when Torres span inside the opposition's penalty box before finishing under Navas following some questionable defending from Los Ticos.
Both managers made changes in the period that followed, with Enrique protecting his key players for the Germany match, while Costa Rica's thoughts had already switched to their next game with Japan.
One of those substitutes, Alvaro Morata, fired wide of the Costa Rica post in the 64th minute, but the fifth arrived in the 74th minute when Gavi brilliantly volleyed a Morata cross into the bottom corner.
Five then became sixth in the final exchanges when Soler fired past Navas from close range, before Morata made it 7-0 with a clever finish after combining with Olmo.