What I'm looking for in music theory is a set of tools to understand
the composition of musical pieces
What is this "understanding"? It means the ability to handle things.
Understanding is a psychological process related to an abstract or
physical object, such as a person, situation, or message whereby one
is able to think about it and use concepts to deal adequately with
that object. ... Understanding implies abilities and
dispositions with respect to an object of knowledge that are
sufficient to support intelligent behaviour.
What is it that you want to do? You do something to an object - a melody. What do you do to it? Do you play it, do you modify it, do you create new variations of it, or do you make arrangements of it? Music theory provides tools for doing those things. If you say that you just want to "understand" without actually doing anything even in an imaginary sense, then ... it seems to contradict the meaning of "understanding". Understanding means having a set of skills and abstractions to act and to behave.
In my opinion, you should be able to play melodies. Claiming to "understand" melodies without being able to actually play any melodies feels impossible. And if someone says they "understand" composition, it means that they have to be able to compose, at least a little bit, at least in some weird way or shape they are able to create compositions. If you can't compose anything and have never composed anything in any way or form, then you just cannot possibly understand composition.
So, start composing! Make a melody. Pick a note, pick another note. Happy? No? Change something.
When you do this, you will probably feel a need for some concepts from music theory to reason about the notes, see the forest from the trees, and to gain perspectives for why your composition creates certain feelings. To communicate your composition to other people. To write down and manipulate your composition. When you have these needs, then start reading music theory.
To help you get started in making sensible melodies, it might be useful to replicate existing ones. Can you play the melody of Happy Birthday by ear? If not, start by doing that, it is a very, very elementary skill. Write down the notes. When doing that you might notice that it's kind of useful to have names for the pitches, or at least well-known locations on an instrument, keyboard or fretboard, musical notation staff or grid in a music application. When those things help you in achieving what you want to do, then I guess they start making sense?
As you already figured out, the piano keyboard itself contains a lot of theoretical concepts of Western music culture embedded into the layout and structure of the instrument itself. It's a very nice way to communicate theory, isn't it? You are able to act as if you understood the concepts ... or actually, by using that instrument you kind of do understand the concepts. Just press the keys! The same applies to most instruments. The guitar has frets, 12 frets per octave - it was a non-trivial decision or development that was done for you a long time ago, to support certain kinds of music in a certain culture. You have taken this "12 notes" thing for granted, as a general law of music. That was actually a slight misunderstanding, but it helped you to progress. I suggest you to take a musical instrument, not question why it is like it is, and start making music. Play notes. Two notes, three notes, you just made a melody.