Not sure I am getting the question right but there is already a built in function for that
If you explain what you are trying to achieve as a higher level question we can be more helpfull cause there is bunchof integrated functionality regarding ScreenToWorld detection, such as location, objects traces etc.
I tried to understand what is going on and my guess is:
When client clicks orange highlights are correct.
However when you switch to other view , which is probabyly the one with render target its not matching.
Since your render target size is not matching the position clicked on the viewport
Not knowing your entire systems created (seems a lot of going on) easiest way to solve it is to,
GetViewport size (XY) and divide it to RenderTarget(XY) this will give the scaling between your viewport and render target. Also since you have padding from left and right you have to compansate that to get actual location rather than a virtual.
If i have padding = 0, then my main viewport with no (borders or widgets/render target) i should be able to click the same position on screen as i am in the world right?
Testing:
+I noticed that the results from the equation are almost equal to the GetMousePosition but not exact.
+I Swapped the the rendertarget and viewport around to consider for BEDMAS my bad.