John Mueller was asked in Twitter if backlinks from high-quality domains that link to 404 pages still pass authority to the domain. His answer was that, if the links go nowhere, they drop it. Recommending something that does not exist anymore is not really a useful recommendation, so they just drop it and not count these 404 links.
As you can see, links that go to 404 pages are a wasted link. It is good practice to look through your site for any pages that could be showing up 404 issues and get them fixed.
Another option is to 301 redirect 404 pages to another page – a recreated page or maybe to the homepage, so as to not waste any link juice that may be coming to those 404 links.
Backlinks are not that easy to come-by, especially if they are high quality links that come from authority sites. Why waste such links by having them go to a 404 page when you can take advantage of the link juice they bring?