NASA and other space exploration programs are funded by respective Governments as we know. Are funds also raised by publishing books on space exploration and related subjects?
There Are Other Funding Sources, But Probably Not Book Sales
NASA's FY17 Financial Report lists three revenue categories on page 33. Two of them are from taxes (Congressional Appropriations). The third revenue source is "Revenue From Agreements". These are agreements with outside entities that may or may not generate revenue, where NASA provides goods and/or services to the other entities. This includes services like launchpad and mission control facilities for corporations like SpaceX.
Regarding media, this page on the NASA web site tells us a lot. Generally, NASA media is free to use, so they won't be getting any money from it:
NASA content - images, audio, video, and computer files used in the rendition of 3-dimensional models, such as texture maps and polygon data in any format - generally are not copyrighted. You may use this material for educational or informational purposes, including photo collections, textbooks, public exhibits, computer graphical simulations and Internet Web pages. This general permission extends to personal Web pages.
News outlets, schools, and text-book authors may use NASA content without needing explicit permission. NASA content used in a factual manner that does not imply endorsement may be used without needing explicit permission. NASA should be acknowledged as the source of the material. NASA occasionally uses copyrighted material by permission on its website. Those images will be marked copyright with the name of the copyright holder. NASA's use does not convey any rights to others to use the same material. Those wishing to use copyrighted material must contact the copyright holder directly.
There is a NASA Gift Shop that sells books and perhaps operates at cost or provides so little revenue it doesn't factor in the annual financial reports. Of the books listed there, almost all seem to be published by entities other than NASA, except for Wings In Orbit. I can't figure out how to tell if Wings In Orbit generates any revenue, or is sold at cost.
NASA does enter into "reimbursable" and "non-reimbursable" agreements of many kinds for goods and services as outlined here: https://technology-larc.ndc.nasa.gov/partnership-info/space-act-agreement
If NASA enters into a reimbursable agreement with a publisher, then they will generate some revenue from that agreement. However, this report suggests NASA may be too often entering into non-reimbursable agreements when it could be getting reimbursement.
I found the following listings in this very long list of active agreements in June 2017:
608 18711 Griffin Media Book on the history, design, construction and utilization of the International Space Station 4/15/2015 4/14/2018 Non-Reimbursable $140,477 JSC SAA-OA-14-18711 386 20048 World Book, Inc. NIAC - World Book, Inc. Agreement 8/13/2015 8/13/2020 Non-Reimbursable $15,000 HQ
If you scroll to the right, you'll see that neither of them are reimbursable.