This wavefunction is an idealization of a wave function that has very very steep, but not discontinuous, behavior at $0$ and $a/2$. You are right, the wavefunction as written is not a proper wave function. That's a good observation.
Often in physics the math is much easier if a real situation is modeled by one that is close to it, but mathematically more tractable. That's the case here. If you had to deal with steep but non-infinite slopes at the boundaries, any integrals that you might have to do would be more difficult. But we expect that the result obtained from a model calculation like this will be very close to the actual physical state of interest.
Another reason for introducing wavefunctions like this is that in introductory courses it allows the focus to remain on the important points, not to be obscured by complicated math.
Another less obvious non-physical aspect of this wavefunction is the perfectly flat top. To achieve that, the wavefunction would have to have contributions from states of infinite energy.
To answer your final question: no. This wavefunction is not physically possible for the infinite square well. But then, the infinite square well is itself not physically possible ...
I strongly encourage you to continue questioning what you read!