The first way is from a shock of massive damage. When the Ark crashed on Earth all of the occupants on board were retconned into emergency stasis lock. At various times during the Beast Wars combatants had to be returned to their respective bases due to going into stasis lock after being badly damaged.
The second way seems to be a more gradual process and can come about from damage and energy depletion. Dinobot was told by his internal computer to go into stasis lock or risk losing his spark. This method is a conscious decision and the Transformer can choose to override stasis lock, unlike the first way which seems to be an unconscious action by the Transformer's on-board computer.
Sometimes it can benefit Cybertronians, especially if they are tired or injured.
The term is used in a different sense here – through the use of Stasis Cuffs a Cybertronian can be prevented from moving or using special abilities without being rendered unconscious or incapable of speech. Sentinel Prime referred to the condition as stasis lock.
Transformers Cinematic Universe
Megatron ended up in stasis lock after crash-landing on Earth in search of the AllSpark where he was found by Archibald Witwicky; Witwicky unfortunately briefly reactivated Megatron's tracking systems which burned a map to the AllSpark on his glasses, partially blinding him and rendering him insane.
Megatron was still in stasis lock at Hoover Dam under the watch of Sector Seven before Starscream took out the dam's power supply and Frenzy disabled the cooling ventilation keeping Megatron frozen. When Megatron woke up after thawing out he was not happy and proceeded to trash the room he was in before transforming and escaping his makeshift prison.
Jetfire, an ancient ex-Decepticon Seeker entered stasis lock on Earth while in the form of the SR-71 Blackbird and ended up in the Air and Space Museum. It is unknown exactly why he entered it but it is probably because of his old age. When Samuel James Witwicky, Mikaela Banes, Leo Spitz and Seymour Simmons found him an AllSpark shard revived him and brought him out of stasis lock; Jetfire displayed no injuries that could have sent him into it (the Allspark shard could have healed that), but had a very hard time getting around and fell apart due to a lack of energon. Despite this he proved to be a very useful source of information and even in his weakened state, proved to be an effective fighter killing both Mixmaster and Scorponok although his ranged weapons apparently didn't work (and one was shown malfunctioning) as he used his fists and Cybertronian Axe.
In the novel Optimus wasn't killed but simply sent into stasis lock for a very long time by Cybertronian standards. In that version he was also only stabbed through the back and not blasted also. When Sam brought him back all he did was bring Optimus out of stasis lock, not resurrect him.
To defeat Unicron, the Thirteen concocted a plan where the youngest of their number, Optimus Prime would enter the Chaos-Bringer and expose his Primus-like Spark to Unicron's Anti-Spark, the resulting interaction knocking both into stasis lock. While Optimus was revived by Quintus Prime's Emberstone, Vector Prime created a time-loop around Unicron with the intent of leaving him comatose forever.
When the Great Cataclysm struck Cybertron the few Primes left rounded up as many survivors as they could and led them underground to wait out the out cataclysm in protective caves where they instructed their followers on how to enter stasis. Left on the surface by Prima, the Predacons attempted to fly to safety before vague instinctual knowledge of stasis lock kicked in and they attempted to seek shelter underground.
Skyquake was in stasis until Starscream and Soundwave awakened him by placing an Energon Cube inside his stasis pod. When Starscream found Megatron floating in space he had no choice but to bring his master to the Nemesis where his body was immediately put into stasis.
Bulkhead was put in stasis by Ratchet to examine the data that was stored in his head. Ratchet examined Bulkhead again after the data was gone from his mind. Bulkhead woke up from stasis when Miko played their favorite song on her guitar.
Unicron was put back in stasis after Optimus used the Matrix of Leadership on his spark.
Bumblebee awakens from stasis after he fell off a cliff.
The possessed Nemesis uses its Stasis Beameam to put Bumblebee, Arcee, Bulkhead, Optimus Prime, Megatron, Dreadwing, Soundwave, Knock Out and the Vehicons in stasis. They were pulled out of it when the humans stopped the possessed warship.
Smokescreen explained to Optimus Prime, Ratchet, Arcee and Bumblebee that he arrived on Earth in a Decepticon escape pod because he was captured aboard and went into stasis. He woke up from stasis when they found him.
After Optimus was crushed by the Decepticons blowing up the Autobot base he went into stasis after he was saved by Smokescreen from capture.
Optimus went into deep stasis and saw Alpha Trion in the AllSpark. Alpha Trion tried to convince Optimus to join the AllSpark, but Smokescreen was able to use the Forge of Solus Prime to revive Optimus in a new body.
Soundwave went into stasis when he was captured by the Autobots after erasing his memory banks. Laserbeak eventually tracked down William Fowler and attached himself to Soundwave's chest thus waking him up.
Unicron awoke from stasis again and used Megatron's body as a vessel to destroy Cybertron.