The responsibilities of the client and the contractor are enshrined within the contract.
Who produces the risk assessment? Can the subcontractor request it from the machine builder?
In accordance with the requirements of the Machinery Directive 2006/42/EC, the risk assessment must be produced as part of the design process. In this case the subcontractor must request the risk assessment, in order to produce the electrical design in accordance with the requirements of the risk assessment.
If you consider it carefully, the subcontractor (electrical design) is not really able to produce a risk assessment, as he is unfamiliar with the machine. A risk assessment must be available to enable the electrical design to be implemented correctly.
It is possible to commission a third party to produce the documentation, but this must be clarified within the contract.
How can a subcontractor deal with a situation where an appropriate safety concept is impossible due to mechanical deficiencies (e.g. protective enclosure is missing or similar)?
The electrical design engineer can only produce the design using the documents made available (risk assessment and safety concept). If deficiencies should arise afterwards, then the client is responsible for bearing the additional costs. In general the electrical company is not familiar with the machine in detail, so it can only refer to the documentation with which it is provided.
Unfortunately it often happens that the subcontractor does not receive the necessary documents, so that heavy costs arise due to the extra work and modifications that are required when putting the machine into service.