Just completed a playthrough of Super Mario Bros. 3. The goal this time was to document the camera/viewport behavior. A surface examination might suggest that the camera logic is extremely complex with many unique conditionals and biased objects attracting the camera but after a thorough playthrough a simpler logic (coupled with informed level design) reveals itself.
There are essentially two types of camera behaviors in SMB3: Free-moving, in which the camera follows Mario, keeping him in the center of the screen (vertically and horizontally) except when doing so would place part of the viewport outside of the map; and Auto-scrolling, in which the camera moves automatically along a predefined path at a predetermined speed (first just horizontally with more complex paths introduced later). The left edge of the screen pushes Mario along, the right edge prevents progress and the bottom edge becomes a bottomless pit (instant death).
This post is only concerned with the first behavior.
There are very few truly Free-moving levels. Those levels are usually two or more screens tall with lots of 30 and 45 degree ramps, one screen-wide vertical shafts, or those where the action takes place entirely underwater.
The remaining Free-moving levels start with the camera locked in a fixed vertical position aligned to the bottom of the level. Mario can jump up and off-screen in certain places (even though there may be platforms somewhere above).
There appear to be two triggers that can release the camera: filling the P-meter (required for flight with Racoon or Tanooki Mario) or climbing a vine. Either can release the camera from its vertically locked position allowing it to follow the player. Once unlocked the camera remains Free-moving until Mario returns to an elevation that allows the camera to lock back onto the bottom of the map.
Some levels ignore these triggers (the most notable example is the secret door to the warp whistle in the first mini-fortress). There are also a few levels that contain multiple rooms, stacked and connected by pipes (the mid-World 5 tower for example). In these rooms, instead of snapping to the bottom of the entire map there are independent, rectangular camera regions that the camera smoothly transitions between when Mario enters a pipe.
Most of the level design in SMB3 is horizontal and only two screens high. Most of the action occurs in the bottom half of each level with the camera locked vertically in place until Mario takes flight or climbs a vine. Because the levels are carefully crafted with these simple rules in mind the camera behavior appears to be much more complex than it actually is.