  Bose-Einstein correlations between identified charged pions are measured for
$p$+Pb collisions at $\sqrt{s_{\mathrm{NN}}}=5.02$ TeV using data recorded by
the ATLAS detector at the LHC corresponding to a total integrated luminosity of
$28$ $\mathrm{nb}^{-1}$. Pions are identified using ionization energy loss
measured in the pixel detector. Two-particle correlation functions and the
extracted source radii are presented as a function of collision centrality as
well as the average transverse momentum ($k_{\mathrm{T}}$) and rapidity
($y^{\star}_{\pi\pi}$) of the pair. Pairs are selected with a rapidity $-2 <
y^{\star}_{\pi\pi} < 1$ and with an average transverse momentum $0.1 <
k_{\mathrm{T}} < 0.8$ GeV. The effect of jet fragmentation on the two-particle
correlation function is studied, and a method using opposite-charge pair data
to constrain its contributions to the measured correlations is described. The
measured source sizes are substantially larger in more central collisions and
are observed to decrease with increasing pair $k_{\mathrm{T}}$. A correlation
of the radii with the local charged-particle density is demonstrated. The
scaling of the extracted radii with the mean number of participating nucleons
is also used to compare a selection of initial-geometry models. The cross-term
$R_\mathrm{ol}$ is measured as a function of rapidity, and a nonzero value is
observed with $5.1\sigma$ combined significance for $-1 < y^{\star}_{\pi\pi} <
1$ in the most central events.
