The imposition of the penalty or security measure will respond to the principles of necessity, proportionality and reasonableness. The principle of necessity will be understood within the framework of prevention and in accordance with the institutions that develop it.