Is a protection diode needed on a TRIAC optocoupler and what for?
Is a reverse polarity protection diode required across the INPUT of an optoisolator?

Summary: 


A diode would often not be used in the location shown BUT it does protect against extreme conditions and costs very little to implement so is not a terrible idea. I have never seen a diode in this location in a "real world" circuit. 
The diode protects against the possible effects of major output circuit switching spikes being capacitively coupled into the input LED. This is not normally a problem. 
The diode provides ESD (electrostatic discharge) protection for the input LED. Whether this is an issue depends on your application. Once in circuit R1 provides as ESD discharge path and the ESD would need to be at a level where this did not provide enough protective load - unusual but possible. 
Almost any diode will do. A (very cheap, very available) 1N4148 would be a good choice. It just has to protect the LED against reverse voltage. 


For the Sharp S108T01 &amp; 2 optocouplers, datasheet here in the circuit at the bottom of page 9 the protection diode D1 on the input would not usually be required but is not a terrible idea.Cost is very low and it may be useful in some cases. 



LEDs are sensitive to damage from quite modest levels of reverse polarity voltage. This diode provides reverse voltage protection for the internal LED. In that circuit there is not a large prospect of there being reverse polarity, so the diode is somewhat of a luxury. In the datasheet on page 4 the LED reverse voltage rating is shown as 6 Volt. This is the voltage at which it may be damaged - even with no current flow. 

Their thinking may be that with an inductive load a large voltage transient can occur on the output and this might be coupled to the input diode via capacitive coupling. Some manufacturers of very high isolation optocouplers (HP / Avago being a good example in selected cases) may specify the amount of coupling between input and output but this is rare. This is usually more of interest with respect to input to output coupling when very high rates of change of common mode voltage on the input may cause output triggering due to capacitive coupling. (Common mode is when both the input leads change together - the LED may remain off throughout but both leads may xchange from eg 0V to 500V in a short period.)

The diode provides ESD (electrostatic discharge) protection for the input LED. Whether this is an issue depends on your application. ESD usually comes from applied fingers of  people who are not using proper grounding. LEDs are more susceptible to this type of damage when reverse biased than almost any other copmmon component. However, once the optocoupler is in-circuit R1 provides an ESD discharge path and the ESD would need to be at a level where this did not provide enough protective load - unusual but possible. 

As a guide, I'm a reasonably careful and conservative designer by most standards (when I don't decide not to be for specific reasons :-) ) and I would not usually consider it necessary to include the diode as shown. However, as Murphy is always looking for opportunities to destroy apparently safe circuits, if there was a substantial inductive load component and especially if the optoisolator was not zero-crossing switched(as this one isn't) then I'd be likely to add the diode. 

Another possibility where diode reverse polarity could conceivably occur is if reverse polarity or AC  is applied to Vcc. This is extremely unlikely in all except experimental circuits.