The economics of descent planning
Normally the pilot wants to descent in an economic manner and also try to keep passenger comfort in mind. Let's start with the "economic" descent: An airplane will generally consume least fuel per distance at its "optimum cruising altitude". The exact altitude is dependent on the type of plane, the wind and weight. For a jet like the 737 you flew with it is safe to assume that this optimum altitude is >FL300 (so above 30,000ft / 10km). In cruise your flight was at FL400 so that was probably near the optimum for your specific flight on that day.
As soon as you start your descent to your destination you are leaving that optimum altitude. This is bad. So you want to start your descent as late as possible.
On the other hand, at the end of your flight you still have some "free energy": The potential energy conserved in your altitude. You also want to use that energy as good as you can. Using that energy means to turn your plane into a glider. Theoretically you shut down the engines and glide down to your destination (in reality the engines are not shut down but just set to the lowest possible thrust setting).
Those two factors give you an optimal "top of descent": The point at which you can reduce thrust to minimum setting for the remainder of the flight and still reach your destination by flying with "best glide speed".
Now in reality this is disturbed by a few factors. Mostly "other traffic" is such a factor. Maybe you cannot start your descent at your preferred location because there is traffic below. Or maybe you expect a certain routing, start your descent at the correct place, but then in the middle of the descent ATC gives a you different routing which maybe a shortcut or a detour. In this case you are now "too high" or "too low".
Your particular flight (undesired level off)
In the case of your flight you can see a suspicious "level off" at about 15:29 in FL280:
It is highly likely that the pilots were on their desired flight path, but air traffic controllers did not allow them to descend any further. The most likely reason for this is crossing traffic, but it could also have other reasons like late coordination between controllers etc.
Fixing the undesired level off
Anyhow, what can you do as a pilot in such a situation? You will need to use engine thrust in order to stay in FL280. Then once ATC allows further descent you will be too high due to your level off and you need to somehow get rid of the additional energy you have. From an economic perspective this is really bad, because you are burning fuel unnecessarily.
But the pilot is not powerless. There is a third resource you have: Your speed. In such a level off you can reduce the speed in order to leave your engines at idle (or at least a low setting). Actually you can see a pronounced drop in airspeed on your particular flight, so that is probably what the pilots did.
Then when ATC finally allows further descent, you are now too high and too slow. So it is time to trade altitude for speed. And that will result in a nose down attitude. The pilot with high passenger comfort awareness will do do this trade slowly, gradually picking up speed. However the more economic way is to do this quickly.
Additionally it may well be possible that the pilots could not reduce the speed as much as needed in order to conserve their desired state of energy. Maybe they needed engine thrust nevertheless. In this case even after trading altitude for speed they are still too high. They now need to get rid of this energy somehow. One way to do so is to use the speed brakes. However braking away the energy means the extra energy just goes to waste. Another option is to just fly faster. If you fly faster air resistance increases exponentially, thus you will also waste some energy, but at least you also get a benefit from that procedure: You'll reach your destination earlier. So the pilots might want to fly even faster than normal and that means an even steeper descent.
Managing passenger comfort while trading altitude for speed
In this situation it is likely that the AP (Autopilot) was engaged. In that case the comfort depends on the programming of the AP and inputs the pilot makes. The "simplest" mode would be "level change" (Boeing, on Airbus the equivalent would be called "open descent") and at the same time set a high speed target for the AP. In this case the AP will set engines to idle and then pitch down in order to gain speed. How much the AP pitches down depends primarily on the difference between current speed and the target speed. It is completely safe to engage "level change" mode and immediately set a very high speed target. But it can lead to an uncomfortable pitch down as you have experienced.
There are a few tactics to make this more comfortable. One way is to engage "level change" but gradually increase the speed target for the AP. The speed will build up slower, but the pitch will feel much more comfortable. Another option is to not use "level change" mode but "vertical speed" mode. In this case the pilot typically sets the speed target to a very low value (so that engines are idle) and then set a defined rate at which the plane should descent. This also causes the plane to pick up speed (if the vertical speed target is set high enough) but this happens much smoother. However it also means that the resulting speed is not controlled by the AP anymore. The pilot needs to closely monitor the resulting speed and readjust the vertical speed as needed.
As a side note, if a pilot is new on that particular airplane type (or AP) or did not have such a situation for a long time it may also be that the pilot is surprised by how strong the AP pitches down and might manage this differently the next time. However this does not make the situation unsafe. In a comment to another answer you wrote that there were two co-pilots on board. This MIGHT indicate that this was a training flight. On the first flights of a new co-pilot an additional "safety pilot" is in the cockpit to monitor and assist or (in worst case) take the position of the new pilot. This would support the theory that the extend of the pitch down might have been unintentional.
Conclusion
To conclude: The descent your experienced was likely the result of an ATC descent restriction. The maneuver was safe and probably the most economic thing the pilots could have done. However more comfort would have been possible and the pilots probably put put economic or workload concerns before passenger comfort. At any rate it is unlikely that there was any danger.