Ultraviolet radiation
Ultraviolet radiation is the only known thing that is both beneficial and carcinogenic at the same time. More specifically, part of the ultraviolet spectrum which highly overlaps with UV-B (280 - 315 nm) causes conversion of 7-dehydrocholesterol (a zoosterol, chemical compound naturally occurring in the skin of animals and humans) to previtamin D3, which then spontaneously isomerizes into vitamin D3. As visible in the picture 1., the previtamin D3 synthesis occurs with a peak at around 294 nm, and virtually none at wavelengths above 310 nm.
Picture 1.: action spectrum of 7-dehydrocholesterol to previtamin D3 conversion; source: www.testudo.cc.
Most of UV-B in the sunlight is already blocked off by atmosphere; the lower the Sun is above horizon, the more thick layer of atmosphere has to be traversed by sunlight and the less UV-B reaches Earth's surface. A rule of thumb says that the Sun has to be at least 45 degrees or higher above horizon (shadows have to appear shorter than objects casting them on the flat ground), or else too little UV-B reaches us for any substantial vitamin D3 production to occur.
Soda lime glass
Windows are made from soda lime glass, which is generally transparent to UV-A but opaque to UV-B, and thus they mostly block off the part of UV spectrum responsible for enabling vitamin D3 synthesis. Pictures 2., 3. and 4. show UV transmittance of soda lime glass from various sources. In this context it could be a problem, but does not necessarily have to be; pet foods are often fortified with minerals and vitamins, including vitamin D. However, vitamin D content present naturally in foods is poor, which could be a concern if you are cooking or otherwise preparing pet food on your own. What is more, vitamin D deficiency sometimes occurs because of gastrointestinal disorders causing its poor gut absorption - however, unlike dietary vitamin D, endogenous synthesis enabled by sunlight is not affected by this, as it bypasses gastrointestinal tract and directly reaches the bloodstream. Additionally, synthesis via sunlight has the bonus property that it is impossible to overdose vitamin D with it - at some point the synthesis reaction reaches equilibrium and vitamin D is degraded as fast as it is synthesized; meanwhile, it is possible to cause vitamin D toxicity via oral ingestion of excessive amounts (it shouldn't be a problem in case of food, though; it is reasonably possible only in case of excessive ingestion of artificial supplements).
Picture 2.: UV transmittance of soda lime glass; source: publiclab.org.
Picture 3.: UV transmittance of soda lime glass; source: dichroic.asia.
Picture 4.: UV transmittance of soda lime glass; source: www.continentaltrade.com.pl.
Additional properties of sunlight
Please also note that enabling vitamin D3 synthesis is not the only benefit of sunlight exposure. UV radiation in sunlight, for example, has been shown to cause nitric oxide production in the skin (source). Nitric oxide is a signalling molecule that causes vasodilation (dilation of blood vessels), which lowers blood pressure and decreases the risk of stroke and cardiovascular disease. Medications like nitroglycerin and amyl nitrite which are taken to alleviate angina (pain caused by insufficient blood flow to the heart muscle) are converted into nitric oxide in the body and this is responsible for their active properties. However, the spectrum enabling nitric oxide production is different than spectrum enabling vitamin D3 synthesis; part of it belongs to UV-A, which passes through soda lime glass.
Conclusion
Sunlight exposure has many potential health benefits beyond enabling vitamin D3 synthesis. For example, it is known to decrease the chance of multiple sclerosis - however, it has been shown that substituting sunlight exposure with vitamin D3 supplementation does not produce such effect.