I used to have similar issues. It is kind of odd to have this with accidental touch enabled but nothing is perfect.
First what type of lock do you have set on the device? Fingerprint, pattern, pin, face ID???
Check your lock timers. Most users set up their screen sleep time but neglect their screen lock time. Since you mentioned that your are accidentally composing and sending texts that would mean that the phone is not locked. If the device were locked you would notice a drain on your battery from the screen being on in your pocket but it wouldn't be able to compose or send texts, make calls or other accidental things similar to this. Go to Settings>Lock screen>Secure lock settings>enter your unlock code>Lock automatically, I prefer and recommend that this be set to Immediately. Some people don't like for the device to lock as soon as the screen turns off and I get that, you just turned the screen off and suddenly remember that one more thing you want to do and now you have to unlock again. I get it but then there is what is happening to you. You turn the screen off and the phone waits 1 or 2 minutes before locking but if you slip it into your pocket and it opens then as long as the screen is on the phone could be doing anything. Sending texts for instance. By locking immediately there is less chance this can happen.
There is also the physical aspects of what is happening. Any perspiration can wake your screen. If you carry the device screen side in, towards your body, and there is the slightest perspiration it is like touching the screen and will keep it awake, or wake it up. This is what lead me to carrying my device screen side out. I am the type that carries my device in a front pocket but I kept finding my device screen on when I would fish it from my pocket, especially in the warmer months. I found that it takes very little perspiration for my phone to sense my leg through the thin material of my pocket and this would keep the phone awake. Perhaps a change like this would be helpful as well.