I know that the Enterprise-E was considered one of the largest ships the Federation ever built and I know that Borg cubes are seemingly much larger than that. What are the largest ships constructed by the Federation and in the Star Trek Universe as a whole?
The largest Starfleet starship to appear anywhere on screen is the upgraded Enterprise-J briefly seen in the episode "Azati Prime". It's described as being "almost 2 miles" in length (i.e. 3.2 kilometers) as compared to Borg cubes which are approx 3 kilometers in length along each edge.
The single largest constructed vessel we see in the Trek TV show is the "Voth City Ship" which measures 9 kilometers from stem to stern. Other artefacts that could vie for the title of "biggest moving structure" would be the Whale Probe (70 kilometers in length), V'Ger (78 kilometers in length) or the Asteroid/Ship seen in For the World is Hollow which measures some 320 kilometers in length
As you can see, the interior of the City Ship is sufficiently large to accomodate hundreds of Intrepid-Class ships.
Within the extended Trek (book) canon, the largest ship mentioned is a "Fury Ship". These are described in "The Final Fury" as being...
"approximately two hundred and eighty kilometers long, seventy kilometers in diameter, and the pylons supporting the pods extend some three hundred kilometers from the center".
The generation ship (spoilers) in For the World Is Hollow and I Have Touched the Sky is listed as being:
"an asteroid, 200 miles in diameter, that is not in any orbit but follows an independent course through the local star system"
Since the plot involves changing the course of the asteroid, I would say that that qualifies without reservation as a "ship".
Two other contenders with less stellar (heh) provenance would be the pre-Director's Cut V'Ger, which was a ridiculous (and ultimately problematic) 82 AUs in diameter (this means that it engulfs the entire solar system), or the Dyson sphere from Relics, which was two hundred million kilometers in diameter, but arguably not a ship.
In short, there are technological structures in Star Trek that are so large that they no longer resemble our conception of a "ship".
"Miles long, with a maw that could swallow a dozen starships," Decker explains that the planet killer uses a pure antiproton beam to carve planets up into rubble. He couldn't tell if it was a ship or a living organism.
This reference says that the Doomsday machine is approximately 2700 meters, about 8400 feet, just under 2 miles.
If we’re counting non-canon, the DS9 book Objective Bajor revolves around an invading species from another galaxy that arrived in a continent-sized generation ship described as approximately 8,000 miles long and which could only travel at impulse.
Tak frowned. "It has an unusual configuration," he agreed, "but it is not unprecedented, surely?"
"The shape, no," Garaia commented. "But the size …" She let her eyes stray back to her instrumentation. "Captain, that vessel is approximately eight thousand miles long, and the wingspan is about twelve thousand miles. We are still almost an hour from its present position at current speeds."
Tak paled, his eyes riveted to the screen. "Eight … thousand … miles?" he repeated in awe. He shook his head in disbelief. "What kind of a craft is it?" he asked.
Garaia shrugged. She was almost as awestruck as he, but she refused to allow her scientific training to suffer as a result. "Captain, the central core of the vessel is eight thousand miles long, and approximately one hundred miles in diameter. That gives an interior surface area of over two million, six hundred fifty thousand square miles. That is the size of a moderate continent."
Bored and slightly drunk though he might be, Tak wasn't stupid. "You mean that ship is some kind of colony vessel?" he asked, leaning forward and staring hard at the image in front of him.
"It would be a logical assumption," agreed Garaia. "And one probably containing several billion inhabitants."
Possibly, the "ISS Charon"
This flagship from the Mirror Universe is described to be
the size of a city, and it is said to have 450 decks; considering that the height of a single deck could be more or less 3 meters, its total height should be approximately 1350 meters, or 1,35 kilometers. Visually it seems that its length is at least four times its height, making it more than 5 kilometers long.
Even Ex Astris Scientia, based on a visual comparation to the USS Discovery, estimates the ISS Charon to be
well over 4 kilometers long.
1. The "size" of a starship could be measured in length, width, an average of the main dimensions, its volume, and so on.
2. In this case, it is the Mirror Universe.
Well, the Voth Fortress ships are 134.5 kilometres long.
Doomsday weapon - even though it's technically not a ship, just the diameter of its opening could swallow a fleet of ships. The Dyson sphere could also qualify as the largest ship, even though it's more like a giant space station with an internal planet-like atmosphere. It was big enough to swallow fleets of ships, Borg cubes would pale in comparison. The Caretakers Array would technically count as a ship, it was the only thing in VOY series that lacked depth and dimensions. Also let us not forget the Crenim Time ship, capable of annihilating worlds from time/space its destruction never matched its size.