The transmission is going into " limp-in" mode. This happens when the transmission computer detects a problem. It will keep it in second gear and record a diagnostic fault code. The transmission computer tells the engine computer there's a problem so the engine computer turns on the Check Engine light.
You'll need a hand-held computer called a scanner to read the fault code(s). As a general rule, if it defaults to second gear right after starting the engine and shifting into drive, suspect a sensor problem. If the transmission starts out in first gear, then stays or goes into second gear right after an upshift, suspect slippage in one of the clutch packs.