The universe itself is encoded with a certain DNA by which it's self-regulated. Likewise, this underlying structure maintains the integrity of the cosmos and thus in time, rishi's, seers and sages came to understand the intricacies of all that Nature reveals to those with the initiative and desire to grasp that which had been kept hidden from the foundations of the world. Such ancient wise men began to unravel certain mysteries and to understand that a myriad of opposites and contrary forces were at work which in turn demanded the observation of certain 'laws' which, were they to be broken will exact penalties for such transgressions.
That's the religious take on it anyway.