Is it because the majority of traffic comes from higher altitude?
Class B airspace (U.S.):
A significant number of aircraft inbound/outbound to the primary airport located in Class B airspace are descending from, or climbing to, higher altitudes. The purpose of the upside-down wedding cake shape is to contain these aircraft within the boundaries of the Class B airspace, where ATC separation is provided to both VFR and IFR aircraft, considering that the further from the primary airport the aircraft is the higher it is likely to be.
The typical, but not always, top altitude of Class B airspace is 10,000 MSL. Also, the shape of the Class B airspace does not always resemble an upside-down wedding cake due to local airspace requirements, terrain, etc. However, the base/bottom altitudes associated with the various shelves making up the Class B airspace will normally be higher the further away from the primary airport the shelf is located.
Source: for the Class B Airspace image below (except the arrows).
Class C airspace (U.S.):
Class C airspace often, but not always, can also be shaped like an upside-down wedding cake, but it generally only has two shelves. Unlike Class B airspace where all aircraft (VFR and IFR) receive positive ATC separation, in Class C airspace positive ATC separation is only provided between IFR/IFR aircraft, and IFR/VFR aircraft.
Source: for the Class C Airspace image below (except the arrows).
The purpose of airspace classes is to establish areas in which regulations are compatible with and appropriate for the type of traffic expected in that area and the ATC services provided for that traffic.
Let's look at Class B airspace, which is where you find the best-looking upside-down wedding cakes. The airspace around most major, high-traffic international airports is Class B. In this environment, lots of large transport-category aircraft are arriving and departing. As they arrive and get closer to the airport, naturally they have to be descending from cruise altitude through the arrival and approach. As they depart and get farther from the airport, naturally they have to climb up to cruise altitude. If you want to encapsulate this traffic in a chunk of airspace, the natural shape is an upside-down cone. To make it simpler to identify the edges of the cone at any given position, the shape is simplified to the upside-down wedding cake.
Why not just extend the airspace to the surface and have a cylinder? Because then you're imposing Class B regulations on all the little planes that are at relatively lower altitudes farther away from the major international airport, and larger planes arriving and departing from lower-traffic satellite airports in the area.
The same logic applies to Class C airspace, which also usually features shelves, albeit simpler and smaller ones.
The airspace designers pay close attention to the traffic flows and terrain around each airport when defining the shapes. For a cool example of this, check out Seattle's Class B:
All of Sea-Tac's runways (and approaches/departures) are oriented north-south, so there are "wedges" to the north and south that reach down to lower altitudes than to the east and west. The Cascade mountain range rises up to the east and southeast, requiring some special cutouts there too, and there are some more rectangular shelves to the east and west to accommodate "downwind" traffic. There's even a very small cutout immediately to the north to exclude traffic in the pattern at nearby KBFI (Boeing Field, officially King County International Airport). It's a great example of how the airspace is customized to fit the expected traffic flows.
Air traffic and instrument procedures need to be protected (be positively controlled airspace). Activity to/from an airport is diagonal (taking off from an airport and climbing, or descending to landing).
That means it's important to have the air near an airport protected, and the funnel (upside down wedding cake) covers the descending/climbing path without covering low lying areas that aren't needed.
The Class B airspace design should be as simple as practical, with the number of sub-areas kept to a minimum. Its vertical and lateral limits must be designed to contain all instrument procedures at the primary airport(s) within Class B airspace.
The circular and stepped shape called a "wedding cake" appears in this description:
If a circular design is appropriate, the airspace may be configured in concentric circles to include a surface area and intermediate and outer shelf sub-areas... The altitude floors of sub-areas should step up with distance from the airport. Determination of sub-area floors should be predicated on instrument procedure climb/descent gradients to ensure containment of the procedures. Sub-area floors may be adjusted to have various floor altitudes considering terrain, adjacent regulatory airspace, and common vectored flight paths that are not on procedures.