Why isn't implementing scientific libraries in software considered equivalent to a publication? In academia, researchers live by the mantra of "publish or perish". This is because the contribution to society that academia gives is the expansion of human knowledge.

However, given the importance of software to conduct research, I don't understand why implementing many algorithms or building API's for research purposes is not equally relevant when trying to get funding.

See, for example, how few papers in math, computer science and software engineering provide source code, despite the entire focus of the paper being on the implementation of an algorithm and its performance in real hardware. 

Moreover, see how much research relies on API's. We have linear algebra API's, calculus, computer visions, physics simulations, etc. Many of which are paid software (e.g., Matlab).

If someone is willing to spend time developing an API for a given subject (a computer vision library, a rendering algorithm, quantum physics / computing simulations) and that software provides new and useful tools in open software and for free so that researchers can conduct their research more efficiently, I don't see how this is not equivalent in usefulness as making a paper.
Software is a research product has value and is seen as valuable, but you as a researcher need to ensure that you extract the value out of it. Extracting value out of any research product requires doing some kind of formal write up and distributing the ideas among the relevant audience. For software, this is many times in the form of a software publication. Many traditional scientific computing journals take a software paper and these papers can do quite well in terms of citations. For example, Shampine's "The MATLAB ODE Suite" is one of the most read and cited articles in SIAM Journal of Scientific Computing.

Taking that paper as a reference, notice that it identifies the problem it's solving, explains how it had to modify the algorithms to achieve its goals, and the kind of results it can achieve. This then gives a citable resource and many of the people who use the paper will then cite this source. Software tends to be under cited, but since it can get so widely used you will find that successful software has some of the most cited publications. Another classic journal like this is ACM Transactions on Mathematical Software (ACM TOMS). More recent software journals are the Journal of Open Research Software and SoftwareX.

In a slightly different direction, the Journal for Open Source Software reduces the importance of the paper by making the software and its documentation part of the peer review. As an example, Optim.jl has a JOSS paper which you can see is much shorter than traditional academic papers, but at least summarizes the value of the software in a citable form. 

When applying for jobs, you'll notice that people naturally assign a different value to software papers. While it is definitely changing, some professors I know take hardline stance that software is just implementation and doesn't extend knowledge and will value it less than other papers (which is why these exact points should be refuted in a publication about said software). In contrast, some individuals care more about impact or citations, and so a widely used software will have a very large effect on them. Generally in my experience, the value of software seems to be increasing over time, with senior professors more likely to take the former stance and newer professors more likely to take the latter.

But my advice would be to just do whatever you think has a high impact to the research community. If it does have a big impact, people will notice, and sometimes just being noticed is what you need.