The people came to a place called Marah and the drinking water there was bitter. They complained to Moshe and he was instructed by Hashem to take the wood of a specific tree found there and cast it into the water and it will become sweet. Moshe did so and the Israelites had water.
Then the Torah continues to tell us: SHAM SAHM LO CHOK UMISHPAT, “…there he gave them a statute and an ordinance…”. (Ex. 15,25) According to Chazal Moshe told them here the laws of Shabbat, the Red Heifer and the business laws.
Why did he give them these laws in this particular place? When you examine these laws you realize that they are very difficult to keep. The Shabbat is certainly difficult for most people at one time or another. The laws of the Red Heifer implied all the laws of purity and defilement. These are very strict and complex. Business laws calling for honesty and integrity are demanding.
This is what Moshe wanted to demonstrate to them at this very place. He showed them that at first the water was bitter but then it became sweet and beneficial. Similarly he pointed out that these Mitzvot may be difficult to abide by but eventually they prove to be worthwhile and offer a more enjoyable life.