At a first glance I would say it comes from two reasons:

You should not flatten the output of the BERT model
You take the sequence output while you have to take only the pooled output.

Look at how it is done in TFBertForSequenceClassification.