Your whipped cream likely became grainy and separated because it was over-whipped, causing the fat molecules to clump together and release liquid. Stop whipping as soon as stiff peaks form.
Whipped cream transforms from liquid cream to a light, airy delight through the process of incorporating air and agitating the fat molecules. When you whip cream, you're essentially unfolding the fat molecules and trapping air bubbles within them. This creates a stable foam structure. However, if you continue whipping beyond the point of stiff peaks, you'll start to break down this structure. The fat molecules will begin to clump together excessively, squeezing out the liquid (buttermilk) that was initially part of the emulsion. This results in a grainy texture and separation of the cream into butterfat and liquid. Factors like the fat content of the cream (higher fat content whips better), the temperature of the cream (cold cream whips faster and more stably), and the speed of your mixer can all influence how quickly this over-whipping process occurs.
If you notice your whipped cream is starting to look grainy, try gently folding in a tablespoon or two of fresh, cold cream. This can sometimes re-emulsify the mixture and salvage it, although it's not always guaranteed.