24:31 is not a valid time: SQL datetime values (which DATEPART expects) cannot represent it as a time so you correctly get the error - which you do not with just a valid time:
SELECT datepart(HH,'23:31')
You will have to look at exactly where the string came from, and work out from that what you can do with it.
We can't suggest anything - we have no idea where you get the value '24:31' from, but the chances are that is comes from your DB and is badly stored - you should never store anything other than true strings as VARCHAR or NVARCHAR - dates, times, numbers: all need to be stored in "proper" columns, not strings. Probably, you need to store it as a number of minutes in an INT instead of string based hours and minutes.