Hydroelectricity is the energy harnessed from water as it flows to a point of lower elevation due to gravity. Solar energy makes this possible because the only way that water can naturally get to a point of higher elevation is evaporation.
Without the sun’s heat evaporating large bodies of water such as oceans and lakes, there would never be rainfall in areas of high elevation, meaning we wouldn’t have streams and rivers. The water cycle that students learn in elementary school wouldn’t exist without the heat source of the sun.
Hydroelectricity relies on the flow of water within streams and rivers, which wouldn’t exist without the sun’s energy heating up bodies of water. So you could say that hydroelectricity is simply harnessing the energy that was supplied to us by the sun indirectly.