That's legit under certain assumptions. If you know the true population standard deviation and are assuming a normal distribution and want to create a confidence interval for the population mean then this is what you would use.

Typically we don't know the true standard deviation so you replace sigma with the estimate and use the t-distribution instead of the z distribution. If you have a large enough sample (typical rule of thumb is n > 30 but I would prefer much greater) you can just use the formula you have even if you're estimating the standard deviation from the sample.