To my knowledge every Starfleet ship we see is commanded by a Captain. From what I know of modern navies: Lieutenants, Lieutenant Commanders, and Commanders can also command ships. I'm just curious as to why, in starfleet, we never see this.
The Memory Alpha article on Starfleet Captains makes several references to Junior Captains, those who've commanded a Starfleet vessel but don't yet hold the rank of 'Captain'.
- Commander Riker, William T. (USS Hathaway, USS Excalibur, and USS Enterprise-D)
- Lieutenant Commander Data (USS Sutherland and USS Enterprise-D)
- Lieutenant Commander Jadzia Dax (USS Defiant)
- Lieutenant Commander Piersall (USS Prometheus)
- Lieutenant Commander James T. Kirk (USS Enterprise)
- Cadet Tim Watters (USS Valiant)
In short, you don't have to be a captain to captain a vessel, but when you do, you're referred to as "captain" regardless of rank. On top of that, most captains are ranked as captains as a recognition of their status within Starfleet and in general recognition that they're competent to lead a large team, head up an important project or be in charge of a vessel.
On a similar note, there are also Senior Captains, those of flag rank who choose to take over a single vessel. Again, these individuals are referred to as "captain" for the duration of their command.
The ranks in Star Trek are taken from the Navy ranks. In the Navy a Captain is not only a rank but also a title. Someone does not have to be a Captain to command a naval ship. But any officer commanding a naval ship is considered the Captain of that ship regardless of their rank. That's why a Commander can be considered a Captain if they command a ship. While on that ship you would be accurate to refer to that commanding officer as "Captain" when addressing them. But on land you would refer to them by their rank.
The other answers address officers below the rank of Captain commanding ships. We can also go the other way, though: James T. Kirk was an Admiral when he commanded the Enterprise in Wrath of Khan.