Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
This is a comment, but I don't have enough reputation points to comment. I think the representations of $\mathrm{SO}(n)$ that have nonzero periods over some embedded $\mathrm{SO}(n-1)$ are the ones that are lifts from $\widetilde{SL}_2$ via the theta correspondence. (So to be clear: I think the answer to your question is "Yes, precisely when $\pi$ is a theta lift from $\widetilde{SL}_2(\mathbf{Q}_p)$".)