A temple is a building that can be built in friendly provinces. Most nations pay 400g for a temple, although there are some exceptions; they can be built by any sacred commander.
Temples perform two main functions:
There are a few other things temples do:
Unlike laboratories, which are generic and stay in a province when it is conquered, temples are nation-specific and are destroyed when a province is conquered, with one or two national exceptions.
Nations with sacred mages will generally build a temple in each fort to allow for recruitment.
Otherwise, how many temples you build will depend on how strongly you need to push your dominion. If it is very important to keep enemy dominion out of your provinces, or shove your dominion into enemy provinces, then more temples can do this.
Most of the time it is very dangerous to build temples outside of forts, as they are destroyed if the province is lost. Some nations have recruitable sacreds outside of forts, and may be willing to take that risk.