"I am the Lord your God who brought you out of Egypt, out of the land of slavery." (Exodus 20:2)
Depending on which tradition you follow, that is either the prologue to the Ten Commandments or the first commandment itself. For present purposes, either way it is the foundation on which the others rest. What does that say about God's intentions and the law's purpose?
In our days we hear a lot of prejudice against religious commandments and following them, with sneers about "blind obedience" or "mindless rule-following", usually complete with God's character being defamed as violent or selfish. Here we see that loyalty to God has a completely different origin. He has already established his benevolence, has already worked to free his people, has already shown his compassion toward them. The Lord is not their oppressor but their liberator. As they stand at Sinai, what he has asked them to do before then has led to freedom and blessing.
The spiritual foundation of keeping God's commandments is his love and compassion for us, the trust that these laws do not bring chains but blessings. He has shown his faithfulness across the generations that separate them from their centuries-gone ancestors who first trusted him, and he will see their descendants through the centuries to come.