It is the simplest solution of the quantum mechanical differential equation with the potential shown below,
Schrodinger's equation is a wave equation, and the functions you show describe waves.
The experimental data , for example the double slit interference patterns for single electrons, showed that the probability of finding the particles has the interference patterns of waves. This simple solution was assigned to describe the wavefunction $Ψ$ of a particle in a box like potential well , with the interpretation that the $Ψ*Ψ$$Ψ^*Ψ$ is the probability of finding the particle at an (x,y,z). The function you show is a general solution , before imposing boundary condition, which bounds will pick either the sine or the cosine.