Saving image in a variable purely through code?

Is there I can save an image in a variable that I have in my assets, purely through code, without attaching it to any game object or prefab? Like path to file or something idk

Yes you can.
if you have that image inside the resources folder you just have to call it:

var spriteImage = Resources.Load<Sprite>("myImagePath");