Moss can grow in sun or shade (there’s more than one kind of moss). What happens over time is that the soil gradually becomes acidic and, if you don’t do pH test and add the correct amount of lime to counteract it, the grass struggles (grass needs pH neutral (7.0)soil to thrive) and starts to die leaving bare spots. Moss, which thrives in acidic soil then starts and creates acidity at an even faster rate so the grass retreats and the moss takes over. Regular pH testing and lime applications would have prevented this. More on that HERE.
Now that the moss is established, you need to kill it with moss killer. Once the moss is dead, rake it out and do your soil pH test (easy) and apply the amount of lime the test indicates you need. Reseed the area (no problems with lime and grass seed together) and keep it moist until the grass is established. Test the soil again in fall to see how you did correcting the pH and apply more lime then if needed. Check the pH every couple of years to prevent his from happening again.