The saucer shape of the main hull is a canon feature for Starfleet vessels in Star Trek, but in pure engineering terms does it make sense?
A starship operates in space at a near zero pressure vacuum while the interior of the ship is pressurized to earth sea level equivalent pressure of 14.7 pounds per square inch or ~2117 pounds per square foot. This represents immense forces to be carried by the pressure hull regardless of the materials used in its construction. The most efficient shape for a pressurized vessel is spherical or cylindrical with hemi-spherical ends. This is why all sorts of pressured tanks, aircraft, space vehicles and space stations use the cylinder shape to minimize weight.
A saucer shaped pressurized volume will always tend to deform toward a spherical shape unless the internal structure is strong enough to resist those forces. Even then, the panels between the internal supports will tend to "balloon" unless they are extremely stiff. This will translate into a very heavy structure. (This is the big reason we have not seen successful blended wing body cargo/passenger aircraft to this date.)
At this point in the discussion many readers will be saying "what about structural integrity fields" or SIFs? The SIF is a Trek construct to reinforce the starship structure. But a SIF requires power; what would happen to a saucer that relied on a SIF to maintain shape when ship's power is lost? The answer is that the saucer would deform and fail due to internal pressure loads if not designed to handle those loads using structure alone. It is inherently a bad design to have your starship pressure hull explosively fail with a power loss!
Matt Jefferies had this in mind when he laid out one of his starship concepts that eventually became known as the "Daedalus Class". That ship had a spherical main hull with cylindrical engineering hull and cylindrical connecting tunnel - a design that is eminently practical from an engineering point of view. Of course the final design of the TOS Enterprise was driven by aesthetics more than engineering, so Mr. Jefferies developed the now classic saucer shaped main hull for TOS.
For 50 years the Trek universe has used the saucer main hull for Starfleet ships, therefore if we think about this from a canon point of view there much be a very good explanation on why to pick such a structurally inefficient shape. Below I attempt to make a canon argument for the saucer shape.
Starship design is a balancing act between the various needs of the structural designer, systems designer, and the propulsion designer. Early spacecraft used structurally efficient and lowest weight cylindrical and spherical shapes for the pressured volumes of the ship. These shapes were adequate for sublight spacecraft, but with the advent of warp drive the external shaping and resulting mass distribution of the ship was increasingly dictated by the warp dynamics.
Warp engines create a "warp bubble" in space-time in which the ship can apparently exceed the speed of light, but the efficiency of the warp bubble is affected by the mass distribution with the bubble. To most efficiently utilize the warp shearing forces, and maximize speed, the mass distribution should be smooth and continuous with the bubble shape. Earth warp nacelles consisted of pairs of warp coils contained with a cylindrical warp nacelle which produces a "sausage" or "hot dog" shaped warp field. It was also found that two nacelles were optimum to provide a "balanced warp field" and good lateral warp maneuverability. When you combine the "sausage" shaped warp field of each nacelle, the result is a flattened bubble shape. At speed the bubble does tend to take on a more flattened teardrop shape due to the trailing edge warp bubble aft shearing forces.
To mimic the shape of the resulting warp bubble, the forward end of the ship should then resemble a flattened ellipsoid or saucer. Early warp 2+ capable earth ships of the 22nd century had a wedge shape with nacelles attached at the wedge extremities for improved lateral mass distribution and better warp dynamics. As speeds increased above warp 3, the warp dynamic shaping of the ship was modified to a full saucer shape with nacelles aft as in the NX design. The saucer provided good lateral and vertical mass distribution within the warp bubble, particularly at the forward end which reduced overall warp shearing drag. The relative placement of the saucer and nacelles in the fore and aft direction were set to keep the mass distribution as smooth as possible longitudinally.
This need for warp dynamic shaping forced structural designers to find new materials and internal structural designs to make the saucer able to resist pressurization loads. Structural Integrity Fields (SIFs) were not a viable option since they were not available in the 22nd century and more importantly that the hull must maintain pressure integrity even in the absence of ship's power. This resulted a much more massive saucer hull structure, but with the benefits of added protection for the crew along with mass to balance the heavy warp coils in the nacelles.
Later when separate engineering hulls developed in the Columbia class (NX Upgrade), the cylindrical engineering hull was located below the saucer to balance the nacelle mass above the saucer centerline as well as overlapping both the saucer aft end and the nacelles to maintain a smooth mass longitudinal mass distribution. The Columbia class and many subsequent engineering hulls also have a "cutout" on the lower aft end which is there to smooth the longitudinal mass distribution in the area of the overlapping nacelles, engineering hull, and nacelle struts.It should also be noted that single warp nacelle ships do exist with saucer shaped main hulls. While not optimum from a warp dynamic point of view, Starfleet kept the saucer shape to maintain continuity of internal layout as crews rotated between various ships. Those ships also have modified warp coils to generate a ‘flatter’ warp bubble, but at the cost of overall warp engine efficiency.