Your question is really broad and not very specific.
I'll try to answer anyway, but i can't go into bit level detail due to time.
For wired internet - as already commented - there are different ways to terminate your access. It goes from blocking your account to physically disconnecting the wires in the central office.
If your access technology is DSL, you usually have a PPPoE Session that gets terminated in the providers network. So you have login credentials that are checked everytime you connect. This can be blocked on "software level".
Depending on your provider this is automated or semi automated. There might be an accounting software running that compares incoming payments versus cost/credit. If it is <= 0 then it might either turn on a red lamp and someones going to check manually and decide what happens or it automatically blocks the access and terminates your PPPOE session. This is pretty much dependent on the implementation.
In former days when there was just POTS and ISDN, field techs would be sent out to the central office exchanges (COE) to cut your wire. I guess these days are long gone in any 1st world countries with full digital telephone networks.
For mobile phones it might sound much easier but is probably more complex.
The way prepaid is handled requires further intelligence, i.e. software. Depending on your provider this software is bought from a 3rd party or developed by the provider itself and hence it's behavior is not standardized.
Also it depends if you just did not pay your invoice once, or are on 0 currency unit credit (for prepaid) or if you failed to pay mutliple times.
You can just be blocked from doing mobile originated calls, or texts, you can be blocked from transmitting data to the internet or you can be blocked completely from attaching to the network (not being able to even receive calls/texts).
What level of "blocking" is applied depends on provider/contract.
Completely blocking you is pretty easy. Your mobile phone - regardless if prepaid or post paid - has a SIM (or eSIM, or other authentication module) with cryptographic keys stored on it. You are authenticating against the network regularly. Within this process the network checks who you are and if you are allowed to do that. If you didn't pay, you are simply not allowed to attach any longer.
More difficult if you are on 0€/$ credit and you are allowed to login/attach, but you are not allowed to place calls.
For prepaid your calls/texts are usally routed via network functions that handle your prepaid contact.
Where i live, 20 yrs ago, you would top up your prepaid account to lets say 10€, then you could send 100 texts for 20 cent each and would end up with -10€ on your account, because the network would recalculate your credit only once a day. Only later they implemented real time account checks that disallowed you to go into negative credit.
So the function that handles each of your mobile originating calls/texts can decide in real time if you are allowed to actually send that text or make that call or not.
If you want more detail on how any of this works, you need to get an understanding of each of the technologies used. Buy/get a book on the topic and you can learn about the signalling of the protocols that are used to understand on which level or where access is blocked typically.
Source: 17yrs Work Experience with a major carrier (started fixed line, mostly mobile though).