First a look at the actual problem; what does your diet looks like? If you stop fasting and the weight comes back it wasn’t the fast that was the issue.
Yes, water retention happens for a bunch of reasons, that’s how the body operates. For starters the ATP molecules, the first source of energy our bodies use, are linked together with a lot of water. As you deplete those through a fast your body releases and excretes all that water. When you finish your fast and start eating again all those energy molecules get rebuilt (which is a good thing) which locks the water back up.
But besides that water fluctuates. Even your salt intake will move it. Heck I woke up 2 pounds lighter this morning than my weight last night; obviously I did not lose 2 pounds of anything else. I think we all gain two pounds over the course of the day so make sure you weight yourself first thing in the morning after going to the bathroom.
But honestly don’t obsess over the scale. Go to Wal-Mart or a thrift store and buy yourself a shirt two sizes too small (or look in your closet, you should have one of those already). Use that as your measuring stick.