Real world explanation:Back when Hasbro was first crafting the Binder of Revelation during the height of the first Movie trilogy era, they had come to a point where they felt they could no longer work the Dinobots into any future fiction with the brand now taking on a super realistic appearance thanks in no small part to the movies. As such, they felt that it was time to retire (perhaps permanently) the Dinobots as characters and had them put to rest until further notice, with Animated being their swan song. Notice at the time that the Dinobots has also virtually disappeared from the IDW G1 comics, having not been seen or heard from since "Maximum Dinobots".
Then, along came High Moon Studios wanting to do a Transformers video game, which they pitched to Hasbro and ultimately got cleared as the starting point for the new Aligned Continuity, coming in the form of Transformers: War for Cybertron.
Prior to this game's completion, however, Matt Tieger of High Moon heard about Hasbro's considering to retire the Dinobots and, being a big personal fan of Grimlock, took it upon himself to convince Hasbro to forgo retiring them. In response, Hasbro challenged him to come up with a believable explanation for not only why the Dinobots would turn into robot dinosaurs in a real world setting (at the time, Hasbro was still of the mindset of the Movieverse, in which they viewed Dinobots as unworkable for its realistic world), but also why they would do so
on Cybertron in the past (which is where/when the games would be set).
As he really really REALLY wanted to use the Dinobots, Tieger accepted this challange and began crafting an explanation. The result was one involving space bridges and experimentation, which will be detailed further below. And the rest is history. The Dinobots came back into the limelight in the comics and have become so heavily showcased that they're gonna finally be put into the movies via Age of Extinction (the current Hasbro team likely has a different mindset from the old one).
In-fiction explanation:Back during the war on Cybertron, Grimlock was the leader of a five-man unit called the Lightning Strike Coalition Force, who were among the biggest and strongest of the Autobots, minus guys like Omega Supreme, Metroplex, and such. As the war raged on, Decepticon scientist Shockwave eventually took an interest in the group and its members.
After Swoop infiltrated a Decepticon energy base, he was caught and captured by Shockwave. His teammates came to save him, but were overwhelmed by swarms of Insecticons and were all captured as well. Seizing opportunity, Shockwave used the five as test subjects for his latest experiments, reformatting them to suit the Decepticon cause and then discarding Sludge to be left for dead after Sludge was of no further use to Shockwave.
As Shockwave had the now-four Autobots at his mercy, he explained the nature his project. Previously, Shockwave had gained access to space bridge technology, and used the sole remaining space bridge to glimpse across time and space at other planets and eras. During his cosmic browsing, his eye was caught by one particular planet: A rather primitive organic world that was once dominated by powerful creatures of awesome size and strength (until a meteor struck the planet and wiped them all out, that is).
Impressed by the sheer raw might and awesomeness of these creatures, Shockwave took inspiration from them in his reconstruction of the Lighting Strike Coalition into the ultimate Decepticon weapon, one created from a symbiosis of intelligence and brutal savagery. However, he did not foresee their escaping (thanks in small part to Starscream) and the four redubbed themselves "Dinobots", with their first order of business after rescuing each other being to pay Shockwave out for his mistreatment of them.
Later, after the war ended but the battles continued, Shockwave eventually managed to re-kidnap the Dinobots (and Ultra Magnus this time) so as to finish what he started. This time, however, having observed how the Dinobots behave with their savagery and sentience, Shockwave declared that the sentience was no longer necessary for his experiments to succeed, as he planned to remove all of Grimlock's intelligence and render him a mindless monster for the Cons to bend to their will.
Thankfully, a quick save by the other Dinobots and Magnus, who had broken free not too long ago, prevent Grimlock from losing his mind and resulted in Shockwave being torn to pieces... only for us to discover that that wasn't the real Shockwave. No, the real Shockwave is safe and sound, and has several realistic avatars of himself that keep him safe from harm's way. The neverending struggle between the Dinobots and Shockwave raged on for thousands of years, having continued to this very day.