Short answer: both files contain the same text, however the formats are different so the sizes are different as well.
Long answer: TXT files usually use 1 byte per character; if your text is normal (no special characters like emoji) the size of the file in bytes is the number of characters (letters, spaces) in the text. This also depends on CR and LF characters and a final end of file which might be added by your text editor or not.
When 1 byte per character is used and the text is normal (taken from a book, for example) only a small subset of all possible ASCII characters is used. As a result, the text could be saved more efficiently by using less bits per character.
Programs like Word or LibreOffice are aware of this and use compressed formats which automatically reduce the length of the file depending on the possible optimizations. However, these formats cannot be read by a plain text editor.
In the case of Word, docx-documents are basically ZIP-files.