Roth IRA

If you make a deposit into a Roth in Jan 2023 for the 2022 tax year and undo it later in Jan 2023 and experience a gain that gets paid to you in Feb 2023, in what year is the gain taxable 2022 or 2023?