It seems like you want the difference in x and y coordinates?
The following will return that using the top left corner point as a reference, like your diagram shows.
You will need to load the raster to your QGIS session as RASTER_A and RASTER_B or modify the script here to reference their names as you have them stored. Run in the python console:
In the case shown below it is showing the shift between RASTER_A in colour and RASTER_B in grey, both in units as well as % of the respective pixel size.
i.e. here RASTER_B is shifted east by ~2 units or ~112% and shifted north by ~1.3 units or ~74%.
rlayer_1 = QgsProject.instance().mapLayersByName('RASTER_A')[0]
rlayer_2 = QgsProject.instance().mapLayersByName('RASTER_B')[0]
#GET BBOX OF RASTER 1
ext_1 =rlayer_1.extent()
# get the origin points of the raster
origin_1 = [ext_1.xMinimum(), ext_1.yMaximum()]
#GET BBOX OF RASTER 2
ext_2 = rlayer_2.extent()
# get the origin points of the raster
origin_2 = [ext_2.xMinimum(), ext_2.yMaximum()]
#GET DIFFERENCE BETWEEN RASTER 1 AND RASTER 2
difshift= [origin_2 - origin_1 for origin_2, origin_1 in zip(origin_2, origin_1)]
#PIXEL SIZE:
pixelhightx = rlayer_1.rasterUnitsPerPixelX()
pixelhighty = rlayer_1.rasterUnitsPerPixelY()
#GET DIFFERENCE BETWEEN RASTER 1 AND RASTER 2 as % of pixelheight
difpercentage = [(difshift[0]/pixelhightx)*100, (difshift[1]/pixelhighty)*100]
#print(difunits)
print("X SHIFT units: %s units" %(difshift[0]))
print("Y SHIFT units %s units" %(difshift[1]))
#print(difpercentage)
print("X SHIFT %%: %s%%" %(difpercentage[0]))
print("Y SHIFT %%: %s%%" %(difpercentage[1]))