I have seen in many instances when people say codes are "insecure".
In the above example, I understand in the fourth instances, under specific context, such as if you are writing your code to check the user input against a password database, your code can be abused to cause a buffer overflow and allow fraudulent user to authenticate. However I don't understand how your code can be abused in the other cases to endanger the user's computer.
Can I know when people say "insecure", is there any chance they really mean either your program can be abused for an attacker's gain, or your program can crash?
Invocation of undefined behavior is always insecure. The first item (array access our of bounds) is automatically in that category. The fourth is just an example of the first, conditional on user interaction (those pesky users). I.e. the potential to overreach an input buffer has the potential to invoke undefined behavior, and therefore insecure.
That leaves the middle two.
Failing to free dynamic memory will eventually lead to operational failure, as the OS will (usually) terminate such a program, under its rules, not yours. When and how this happens isn't the concern; that it can happen at all is a big concern. This is an ingredient of "crappy code", but moreover has the potential for a security issue. Whatever conditions are required to repeat the leak need only be done with extreme prejudice until such time as the OS tears down the application, and with that you have a DoS (denial of service) accomplishment.
Dangling pointers are just UB laying in-wait. They are yet-more ingredients in crappy code. Just sitting there, they don't do anything. However, they present an opportunity for such a problem when they are dereferenced. Once that transpires it joins the first and fourth items in the basket of UB, and is therefore automatically "insecure". It can also become problematic when the value of the pointer itself is treated as a state unto its own, though that is highly situational and rarer than the simple dereference workflow.
The short answer is: all UB is automatically insecure. Two of the four items present instantly fit into that basket. A third potentially fits into that basket under the right usage conditions. The fourth (failing to free memory) is a flat-out bug that will eventually lead to process termination outside the purview of you, the code author, but is enhanced if exploitable to promote a DoS conclusion.
The super short answer: Don't write code that invokes UB, and don't write crappy code in-general.