You got me curious too. The most logical explanation seems to be that the practice of rock stacking is sort of a prayer or meditation, so it makes sense that there might be rock stacks at a temple. The origin seems to be religious, but in modern times, it's a very popular practice and there are apparently rock stacks all over Korea now. (And they do it in variety shows, too, haha)
An interesting note: including those stacks in a historical drama might actually be an anachronism! I wonder if the director/writer knew that the modern audience would interpret the rock stack as mentioned in this article, "Each stone within the stack represents a particular wish and possibly, family member." Which is apparently kind of a modern interpretation of a rock stack. Not that rock stacks didn't exist back then; they probably did, and were made by the monks, not regular people.
This is just my interpretation, though :) Maybe someone knows more about it.
These are some links:
Buddha's Stones: A Stacking Comparison
Stone Pile and Wishes of Common People (this is about the modern practice)
Tradition: Korea Rock Stacking and Balancing (about the towers built by one specific monk, pretty interesting)