From the Wikipedia article on Erik V:
As an adult ruler, Eric tried to enforce his power over the church and
nobility. In the 1270s, Eric Glipping attacked Småland. His conflict
with the church was brought to a satisfying result, with the help of
the pope. By 1282 he had so offended the nobles throughout Denmark
that he was forced to accept a charter (Danish: håndfæstning - a kind
of a Danish Magna Carta) which limited his authority and guaranteed
the ancient rights and customs which preserved the power of the
nobles.
In other words, the story is very similar to the introduction of the Magna Carta in Britain. We are talking about times before absolute monarchy, the king had to rely on his vassals to enforce his will - all vassals had their own armies that weren't much smaller than that of the king. Support from the vassals was essential when going into war with other countries, and occasionally the king would even ally with some of the vassals against the others. However, in a situation where all vassals were united against the king (and this was apparently the case here) the king had no power to confront them - fighting was not an option, Erik V had to sign.
Why this didn't happen earlier: limiting the power of a king with a charter isn't an obvious thing to do, it is very likely that the Magna Carta served as an example. Of course there were other kings after Magna Carta and before Erik V but their interests most likely didn't bring up the majority of the vassals against them.