Suppose there is an international flight from HEL to JFK with Finnair followed by a domestic flight in the same itinerary from LGA (with American Airlines) 4 hours after the arrival of the Finnair flight. What happens if 4 hours will not be enough for going through immigration/security or transferring? Will AA replace my ticket free of charge and let me take the next plane? I'm confused because there is no way for them to know whether I actually didn't have enough time e.g. due to long lines in immigration, or just missed their flight purposely for whatever reason.
The airlines have minimum connection times that are typically based on actual statistics so if they sell you a single ticket you have a good chance of making it.
However, it's never guaranteed and there are a lot of thing that can go wrong. Immigration, traffic, delays, etc. so there is a non-trivial chance so you will miss it.
Since it's a single ticket, AA will put you on the next available flight. They may comp you for food or hotel, but I don't think there is a clear policy for this specific case. If AA is at fault (delayed flight), they typically will provide. If you are at fault, they won't. If it's in between (weather, traffic, immigration), it's more murky and often at the discretion of the gate agent. You'll have to ask (nicely) and see. Sometimes it helps to talk to a different agent, if you don't get anywhere with the first one.
If things go well, you should be able to make it. Maybe one hour to get your bags and get through immigration https://awt.cbp.gov/, half an hour to wait for the bus plus 60 minutes or so for driving
https://www.nycairporter.com/ourservices/laguardiatojfkshuttle/ gets you to La Guardia 90 minutes before departure. Check in closes 45 minutes before departure (not sure about bag drop). If there is no bus coming soon, you can opt for a ride share (Uber, Lyft), which may be $40 or so. New York traffic can be messy and unpredictable.
I still would recommend against booking this: it's quite a bit of extra hassle (and also some extra money) to get from one airport to the other and you need to drag your bags along. The transfer of your luggage and yourself between airports is entirely your responsibility.
If you book it on one ticket, then yes, they will accommodate you, and move you for free on another flight.
Note that this 'other flight' could be much later, or the next day, or with a detour, depending on where seats are available; so it is typically inconvenient.
Unless your delay is absurdly long, they will probably believe you - the assumption is that if you want a longer break in the city you would book accordingly, so you had control over the duration and connecting flight.