Why would an artificial horizon's roll axis be different on ground and in flight?
The problem
As already pointed out in some of the comments, this is a structural problem of using an IMU-only AHRS unit. This unit cannot distinguish between acceleration due to centrifugal force, and acceleration of the earth.
For example imagine that you fly level, and then roll into a coordinated turn. The short-term roll-rotation will be picked up by the gyroscope, however in the coordinated turn itself the AHRS only &quot;sees&quot; a constant acceleration through its local z-axis (because you are in a coordinated turn). The gyroscopes on the other hand, will not see any movement at all. Therefore the filter will (over time) assume level flight. In essence, you cannot distinguish between gravitational forces and centrifugal forces in forward flight with the accelerometer alone.
Ways to solve this problem
I am aware of two ways of fixing this problem:

Buy a good gyroscope: If you buy a very good gyroscope, you can simply use its measurements and completly omit the accelerometer. However even good MEMS Gyroscopes still have considerable drift (typically you will notice an roll-angle drift after a couple of minutes). If you are willing to spend your life savings (I belive the price tag is 250k$) on a Ring Laser Gyroscope, you can also solve your problem. Fun fact: A couple of flat earthers bough one of these devices and ultimatively measured the earths rotation...

If you are on a Budget however, it may be cheaper (and more reliable) to give your algorithm some sort of velocity feedback. Typically, this is either a GPS unit (which not only produce a measurement of position, but also a velocity measurement), or a velocity measurement based on a pitot tube. With this measurement available, the centrifugal force can be calculated and be accounted for.


Implementation
How can you implement this in software? Well either you take existing projects from any of the common flight controllers like Ardupilot, or betaflight and adapt these to your needs (not knowing your hardware, I cannot tell you how labor-intensive this will be). Or you try to program your own estimation unit based on your IMU and velocity sensor. Before you try to figure out everything by yourself, I would recommend to first take a look at existing Software, which already implements everything necessary. In a nutshell, you just have to program a relatively simple Kalman filter based on the known equations of motion of a 6-DoF point which also estimates the gyro offsets. A very good example of how such a filter is designed can be found on the PX4 project (yet another flight control stack), which details how their Kalman filter is built up. One (open access paper) detailing such an implementation can be found here. I would regard this as the state of the art, and how one would commonly address this problem. The block diagram is displayed here:

Another implementation hinging on a simpler complementary filter, is described in this paper. Based on some minor assumptions it removes the centrifugal force via the airspeed, and uses the centrifugal-force-free acceleration as an input to a complementary filter. Although the used IMU is very high quality, and no algorithm for bias and drift compensation is used, you might get this to work with some adjustments. The block diagram is quite compact:

Disclaimer: I have no affiliation nor contact with any of the authors of the aforementioned papers. I do not own any of the images displayed here, these are directly taken from the papers.
P.S.: Interestingly enough, I also came across this link which offers some bounty for an open-source software implementation of such an AHRS unit.