WARNING! WARNING! WARNING!
It seems that the problem comes from the battery. Apple iPhone 3GS is powered by an internal 3.7 V 1219mAh rechargeable lithium-ion polymer battery and is designed to retain up to 80% its original capacity after 400 full charge and discharge cycles. Such a battery tends to expand after a certain period of time. The expanded battery applies force in all directions causing the logic board to push up. The touch screen also gets pushed up and may break the LCD screen.
If you still have iPhone 3GS, you should consider replacing the battery sooner rather than later. You might also consider a trade-in. It is always a good advice to visit your local Apple store and see what they have to say about it.