I agree with other answers and comments that it's tricky to use triggers to keep the number of comments updated perfectly. You would think this would be reliable, but in practice it isn't.
But to answer your question, here's a demo:
I created tables as you show in your question, then add a row to posts:
insert into posts set post_id = 1, post_subject = 'subject';
Here's the trigger:
create trigger updNumberOfComments after insert on comments
for each row
update posts set numberOfComments = COALESCE(numberOfComments, 0) + 1
where post_id = NEW.post_id;
This trigger is simply one statement so I was able to write it without a BEGIN...END block. But if you do anything that requires a block, then you should read about using DELIMITER.
Then add a few comments:
insert into comments set comment_id = 1, comment_text = 'comment 1', post_id = 1;
insert into comments set comment_id = 2, comment_text = 'comment 2', post_id = 1;
insert into comments set comment_id = 3, comment_text = 'comment 3', post_id = 1;
Confirm that it incremented the number of comments:
select * from posts;
+---------+--------------+------------------+
| post_id | post_subject | numberOfComments |
+---------+--------------+------------------+
| 1 | subject | 3 |
+---------+--------------+------------------+