I am a F-1 student, my visa has expired but my passport is still valid, I am also still enrolled in school and my case for adjustment of status (permanent residency) is pending. Will I get in trouble if the flight from Puerto Rico to the US or from the US to Puerto Rico is diverted to a foreign territory (Haiti, Dominican republic...) for whatever reasons (Bad weather, plane issues...)?
Your student status would be unaffected if your flight has to make an emergency landing in another country. Nor would it be if you travelled there yourself.
People in the US on student visas (F and J) do not need a valid visa to re-enter the US under the automatic revalidation scheme, if they traveled to Canada, Mexico, or certain Caribbean islands, for a maximum of 30 days outside the US. Under automatic revalidation, you re-enter the US in your existing status. You should have a copy of your I-94 and I-20 with you (you may need these anyway when departing Puerto Rico).
The official rules for automatic revalidation, as given to air carriers, are available in the Automatic Revalidation Fact Sheet.
However, since you are applying to adjust status to permanent resident, this is much more complicated, and you cannot rely on automatic revalidation. Leaving the US while your application is pending, without advance parole, is considered abandoning it. How this hypothetical situation would affect your application for permanent residence isn't something we can help with here; try our sister site Expatriates for that question.