When I wrote the War FTP Daemon in 1996, as freeware, this became a problem to me. I did want to give away my work for free, but I did not want any government agency to abuse it. So I came up with a solution - a GPL license with an additional clause - that the government - any government - could not use it for any purpose.
Someone actually complained to the Free Software Foundation about this clause, and they concluded, at that time, that it was permissible.
In years to follow I received many emails from universities, schools, hospitals, research facilities - with requests to use the software. In most cases I granted them permission. But by doing it this way, I could sleep well at night - knowing that my software could not - legally - be used to separate children from parents, or for any other evil purpose by any governments around the globe.
----
War Software series Copyright (C) 1996 - 2018 by Jarle (jgaa) Aase (www.jgaa.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation version 2 of the License - WITH THE FOLLOWING RESTRICTIONS:
* GOVERNMENTS, GOVERNMENTAL AGENCIES OR COMMERCIAL
COMPANIES OWNED 50% OR MORE BY THE GOVERNMENT ARE
NOT ALLOWED TO USE THE SOFTWARE OR SORCE CODE FOR
ANY PURPOSE. THIS RESTRICTION ALSO APPLIES FOR
PROGRAMS DERIVED FROM THE SOURCE CODE, OR PROGRAMS/
SOURCE CODE THAT USE SPECIAL TECHNICS/ALOGRITHMS
INVENTED IN THIS SOFTWARE.
* THE FULL SOURCE CODE IS WITHELD FROM A PUBLIC RELEASE
UNTIL THE LINUX VERSION IS RELEASED.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.