We report on the first measurement of the direct $CP$-violating asymmetry ($mathcal{A}$) in the charmless decay $B^0 to K^0pi^0$ at Belle II and an updated measurement of its branching fraction ($mathcal{B}$). We use a sample of electron-positron collisions collected in 2019 and 2020 at the $Upsilon(4S)$ resonance and corresponding to $62.8$ $text{fb}^{-1}$ of integrated luminosity. We reconstruct and select about $50$ $B^0 to K_S^0 pi^0$ candidates, and we measure $mathcal{A}_{{K^0pi^0}} = -0.40_{-0.44}^{+0.46} (text{stat}) pm 0.04 (text{syst})$ and $mathcal{B}(B^0 to K^0 pi^0) = [8.5_{-1.6}^{+1.7} (text{stat}) pm 1.2 (text{syst})] times 10^{-6}$. This is the first measurement of $CP$ violation in $B^0 to K^0pi^0$ decays reported by Belle II. The results agree with previous determinations and show a detector performance comparable with the best Belle results.