The episode where the Enterprise discovers a Dyson sphere is “Relics.” In the sixth-season episode of Star Trek: The Next Generation, the Enterprise-D investigates a distress signal and finds the wrecked USS Jenolan lodged against the sphere’s outer shell.
The crew also discovers that Montgomery Scott, the former chief engineer of Captain Kirk’s Enterprise, has survived inside the Jenolan’s transporter pattern buffer. Geordi La Forge restores him, bringing Scotty into the 24th century and creating the episode’s central character story about adapting to a future that has outpaced him.
“Relics” presents a Dyson sphere as a vast artificial shell surrounding a star. The concept was proposed by physicist Freeman Dyson in 1960 as a thought experiment about an advanced civilization harvesting stellar energy; it is not a solid planet-sized shell in the usual scientific interpretation. A common mix-up is identifying “Relics” as merely the Scotty episode, since its emotional focus is his return, but the Dyson sphere drives the Enterprise’s main danger and plot.