You get a backlink from edu and gov blog, but it has nothing to do with your niche. Does Google then give this backlink less weight?
It will just be treated like a normal link. As long as it is a dofollow link then you have a good back link.
Google gives backlink weight depending on the page rank and authority. If you got a link from an edu or a gov blog, then it'll have more weight. The most important thing is how many links to you have on your site's pages that can leak the page rank out of your sites. You should do interlinking between your website, but not link out to many other sites.
.edu and .gov sites are always much trusted sites according to Google. If you will get a link from these sites it will be highly beneficial then any other link even if the site is not related to your theme. But getting backlink from .edu or .gov sites is very-very difficult and for this a site has very good quality and a great information resource on some topic.