That is quite illegal, which means it is bad news for you. When you are just starting out to learn electrical, seeing bad work can lead you to *doing* bad work. You must be on guard against that.
One of the first rules of electrical is that wiring layout/topology must be in a *tree* format with branches only, and must never loop back upon itself. That is because of a very important rule: Currents must be equal in each cable or conduit.
Take a healthy switch loop: If X amount of current flows down the always-hot wire, then X amount must flow back the switched-hot wire. That works fine.
But now look at yours: with the 2nd circuits' hot capped off, the current for that other light flows down your alwaysh-hot wire, and then back out *another cable's* switched-hot wire. Currents are now not equal in those two cables. That creates a series of issues with EMFs causing emission and vibration, eddy current heating, all sorts of wacky stuff. Remember, this is AC power. It does not behave like low voltage DC.
It causes a second problem, though: Current is coming off "your" circuit's hot wire, and returning on "the other" circuit's neutral wire, along with all the other current on that circuit. Why care? Neutrals don't have breakers. If 1 neutral has to return 2 circuits' worth of power, it can cheerfully return 15A from both of 2 circuits and wind up carrying 30A on a 15A wire.
(notwithstanding MWBC; let's not get into that).
I suspect there is no problem with that. I gather they did this because they wanted both lights on the same switch. Some novice got in there and figured out this would work. Bad hack.
What I just said about "tree topology" and "currents must be equal" and "neutrals don't have breakers"...
Terrible idea. Quantity doesn't make a difference. The next person might decide to put a switch-receptacle there so they can power a vacuum cleaner and now suddenly there's 15A on that "inconsequential" neutral steal.
Also, stealing neutrals does not play well with GFCI/AFCI. That means down the road when someone fits one of those, it immediately trips, and forces them into a "Bug Hunt" - searching the entire circuit for any sort of unexpected cross-connection or sharing of neutral. If it's the new owner, they could even file a claim on it, and you could get stuck paying for the half day of an electrician's time to tear apart half the house looking for the hack.
Further, there's no legal or safe way to bring just a single wire from the recep box to the switch; the wiring method rules require you to bring a whole cable. Since you're bringing the whole cable *anyway*, why not just use the hot wire also, to install this *properly* as a normal non-switch-loop? Disconnect and cap off the supply up in the lamp box at that point.
Because your mindset was to hack/run experiments, and electricity is dangerous. You were "faking it" with as little learning as possible ("I did a little googling"). Googling doesn't work because it only answers questions. Without a well-rounded primer on the subject, you have no idea which questions are important to ask! This is the source of an unbelievable amount of hack-job work.
The most efficient way to get a well-rounded primer on the subject is from a book on home electrical, and reading it through and through to learn how the concepts overlap.
The problem with experimenting to find a solution (instead of understanding and planning to find a solution) is there are lots of combinations that will seem to work, and then, will kill you! Electricity is very unforgiving like that, and a rank novice can be a menace. But "skilling up" solves that nicely.
Unfortunately the vast majorty of smart people couldn't care less and just want to install their smart switch. If you don't want to develop the domain knowledge, then hire it done, but that seems like a waste. Once you gain competence in electrical, not only can you save stupid amounts of money, any project you want can be accomplished.
Hopefully not. But the #1 question I see is "I did something wacky, and a part of the circuit stopped working" - and we chase the problem down and it turns out to be a failed backstab connection somewhere upline. Speaking of "bug hunts"...
You never said anything about a "red wire". That means either you have a modern switch loop that *does* have a capped off neutral (maybe pushed into the back of the box where nobody looks), or you have a multi-wire branch circuit (MWBC) and that is a whole 'nother kettle of fish. An MWBC is an engineered way to share a neutral across two hots, that exploits a unique feature in North American wiring to do it safely.