Generally, the Hilbert space for the infinite square well is taken as
$$
L_2([0,\pi]) = \left\{f:[0,\pi]\to \mathbb C \ \middle| \ |f|^2 \text{ is Lebesgue integrable, } \int_0^\pi|f(x)|^2\mathrm dx<\infty\right\},
$$
so the answer is yes.
On the other hand, your function doesn't satisfy the conditions we require of the set of physical states in the well, nor does it belong to the domain of the hamiltonian, both of which are strict subsets of the Hilbert space.
It is an uncomfortable fact that some* configurations in QM involving infinite-dimensional Hilbert spaces give rise to states which live in the Hilbert space of the problem but which we're unwilling to consider as physical states. This is an unfortunate consequence of the fact that we like the closed-under-infinite-superpositions property of Hilbert spaces, but the conditions we like to impose on states to call them 'physical' are not closed under those infinite superpositions. So, you know, ugh. But it is what it is, and we just do our best to keep things as well-labelled as we can.
*actually, by "some", I mean all configurations in QM involving infinite-dimensional Hilbert spaces. This behaviour is generic and it appears everywhere - examples are easy to come up with.